-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit addresses inconsistencies from Postgres' behavior. First, it makes the `BPCHAR` type distinct from `CHAR`. The former is a blank-padded character type with no type width, meaning that it could have any length. The latter is a blank-padded character type with a type width of exactly 1 - it is essentially an alias of `CHAR(1)`. Previously, a column of type `BPCHAR` behaved the same as a column of type `CHAR(1)` - it enforced a length limit of 1. Second, the typing of `CASE` and `CASE`-like expressions has been fixed. The branches of these conditionals is no longer forced to have the same type-width. Fixes #127889 Fixes #108360 Release note (bug fix): A bug has been fixed that caused incorrect evaluation of `CASE`, `COALESCE`, and `IF` expressions with branches producing fixed-width string-like types, such as `CHAR`. In addition, the `BPCHAR` type has been fixed so that it no longer incorrectly imposes a length limit of 1.
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
query T | ||
SELECT 'foo'::BPCHAR | ||
---- | ||
foo | ||
|
||
statement ok | ||
CREATE TABLE t (c BPCHAR PRIMARY KEY, FAMILY (c)) | ||
|
||
statement ok | ||
INSERT INTO t VALUES ('foo'), ('ba'), ('c'), ('foobarbaz') | ||
|
||
query T rowsort | ||
SELECT c FROM t | ||
---- | ||
foo | ||
ba | ||
c | ||
foobarbaz | ||
|
||
query T | ||
SELECT create_statement FROM [SHOW CREATE TABLE t] | ||
---- | ||
CREATE TABLE public.t ( | ||
c BPCHAR NOT NULL, | ||
CONSTRAINT t_pkey PRIMARY KEY (c ASC), | ||
FAMILY fam_0_c (c) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# LogicTest: local | ||
|
||
# Regression test for #127889. CASE-like expressions should not impose type | ||
# widths of one branch on other branches. | ||
subtest regression_127889 | ||
|
||
query T | ||
SELECT CASE WHEN true THEN 'foo'::TEXT ELSE 'b'::CHAR END | ||
---- | ||
foo | ||
|
||
query T | ||
SELECT COALESCE(NULL::CHAR, 'bar'::CHAR(2)) | ||
---- | ||
ba | ||
|
||
query T | ||
SELECT IF(false, 'foo'::CHAR, 'bar'::CHAR(2)) | ||
---- | ||
ba | ||
|
||
query T | ||
SELECT CASE WHEN false THEN 'b'::CHAR ELSE 'foo'::TEXT END | ||
---- | ||
foo | ||
|
||
query T | ||
SELECT (CASE WHEN false THEN 'b'::CHAR ELSE 'foo'::TEXT END)::CHAR | ||
---- | ||
f | ||
|
||
query T | ||
SELECT (CASE WHEN false THEN 'b'::CHAR ELSE 'foo'::TEXT END)::BPCHAR | ||
---- | ||
foo | ||
|
||
query R | ||
SELECT CASE WHEN true THEN 1.2345::DECIMAL(5, 4) ELSE NULL::DECIMAL(10, 2) END | ||
---- | ||
1.2345 | ||
|
||
query R | ||
SELECT CASE WHEN false THEN NULL::DECIMAL(10, 2) ELSE 1.2345::DECIMAL(5, 4) END | ||
---- | ||
1.2345 | ||
|
||
subtest end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.