Skip to content

Commit ddcf88a

Browse files
authored
Merge pull request #2152 from dolthub/fulghum/bpchar
Bug fix: allow `bpchar(N)` casting
2 parents 70aa569 + ad04ee5 commit ddcf88a

3 files changed

Lines changed: 46 additions & 2 deletions

File tree

postgres/parser/parser/sql.y

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ func (u *sqlSymUnion) vacuumTableAndColsList() tree.VacuumTableAndColsList {
717717
%token <str> BOOLEAN BOTH BOX2D BUFFER_USAGE_LIMIT BUNDLE BY BYPASSRLS
718718

719719
%token <str> CACHE CHAIN CALL CALLED CANCEL CANCELQUERY CANONICAL CASCADE CASCADED CASE CAST CATEGORY CBRT
720-
%token <str> CHANGEFEED CHAR CHARACTER CHARACTERISTICS CHECK CHECK_OPTION CLASS CLOSE
720+
%token <str> CHANGEFEED BPCHAR CHAR CHARACTER CHARACTERISTICS CHECK CHECK_OPTION CLASS CLOSE
721721
%token <str> CLUSTER COALESCE COLLATABLE COLLATE COLLATION COLLATION_VERSION COLUMN COLUMNS COMBINEFUNC COMMENT COMMENTS
722722
%token <str> BLOCK_COMMENT HINT
723723
%token <str> COMMIT COMMITTED COMPACT COMPLETE COMPRESSION CONCAT CONCURRENTLY CONFIGURATION CONFIGURATIONS CONFIGURE
@@ -12047,6 +12047,11 @@ character_base:
1204712047
{
1204812048
$$.val = types.String
1204912049
}
12050+
| BPCHAR
12051+
{
12052+
$$.val = types.MakeChar(0)
12053+
}
12054+
1205012055

1205112056
char_aliases:
1205212057
CHAR
@@ -15115,6 +15120,7 @@ col_name_keyword:
1511515120
| BIT
1511615121
| BOOLEAN
1511715122
| BOX2D
15123+
| BPCHAR
1511815124
| CHAR
1511915125
| CHARACTER
1512015126
| CHARACTERISTICS

testing/go/enginetest/doltgres_harness_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ func columns(rows pgx.Rows) (sql.Schema, []interface{}, error) {
865865
colVal := gosql.NullBool{}
866866
columnVals = append(columnVals, &colVal)
867867
schema = append(schema, &sql.Column{Name: field.Name, Type: gmstypes.Int8, Nullable: true})
868-
case uint32(oid.T_text), uint32(oid.T_varchar), uint32(oid.T_name), uint32(oid.T__text):
868+
case uint32(oid.T_text), uint32(oid.T_varchar), uint32(oid.T_name), uint32(oid.T__text), uint32(oid.T_bpchar):
869869
colVal := gosql.NullString{}
870870
columnVals = append(columnVals, &colVal)
871871
schema = append(schema, &sql.Column{Name: field.Name, Type: gmstypes.LongText, Nullable: true})

testing/go/types_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,44 @@ var typesTests = []ScriptTest{
349349
},
350350
},
351351
},
352+
{
353+
// https://github.com/dolthub/doltgresql/issues/2145
354+
Name: "bpchar type",
355+
Assertions: []ScriptTestAssertion{
356+
{
357+
Query: "create table bptest1 (pk int primary key, c1 bpchar, c2 bpchar(12));",
358+
Expected: nil,
359+
},
360+
{
361+
Query: "insert into bptest1 values (1, '1', '1');",
362+
Expected: nil,
363+
},
364+
{
365+
Query: "select * from bptest1;",
366+
Expected: []sql.Row{
367+
{1, "1", "1 "},
368+
},
369+
},
370+
{
371+
Query: "SELECT '!'::bpchar;",
372+
Expected: []sql.Row{
373+
{"!"},
374+
},
375+
},
376+
{
377+
Query: "SELECT '!'::bpchar(1);",
378+
Expected: []sql.Row{
379+
{"!"},
380+
},
381+
},
382+
{
383+
Query: "SELECT '!'::bpchar(2);",
384+
Expected: []sql.Row{
385+
{"! "},
386+
},
387+
},
388+
},
389+
},
352390
{
353391
Name: "Character type",
354392
SetUpScript: []string{

0 commit comments

Comments
 (0)