Skip to content

Commit

Permalink
sql: fix column_default in info_schema so literals are quoted
Browse files Browse the repository at this point in the history
fixes cockroachdb#96098

In bc3fccd, the format flags were
changed to use FmtPgWireText for
information_schema.columns(column_default). This does not work for
string literals, since that format does not wrap literals in single
quotes.

Now we've changed to FmtParsableNumerics, which does properly add
quotes, and also avoids adding the `:::` type annotation as
FmtPgWireText does.

No release note since this bug was never released.

Release note: None
  • Loading branch information
rafiss committed Feb 6, 2023
1 parent 899c911 commit c97d4e6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/sql/information_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ https://www.postgresql.org/docs/9.5/infoschema-columns.html`,
colDefault := tree.DNull
if column.HasDefault() {
colExpr, err := schemaexpr.FormatExprForDisplay(
ctx, table, column.GetDefaultExpr(), &p.semaCtx, p.SessionData(), tree.FmtPgwireText,
ctx, table, column.GetDefaultExpr(), &p.semaCtx, p.SessionData(), tree.FmtParsableNumerics,
)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/enums
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,8 @@ WHERE
ORDER BY
column_name
----
y hello
z hello IS OF (test.public.greeting, test.public.greeting)
y 'hello'
z 'hello' IS OF (test.public.greeting, test.public.greeting)

# Test computed columns with enum values.
statement ok
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/information_schema
Original file line number Diff line number Diff line change
Expand Up @@ -2410,7 +2410,7 @@ WHERE table_schema = 'public' AND table_name = 'with_defaults'
----
table_name column_name column_default
with_defaults a 9
with_defaults b default
with_defaults b 'default'
with_defaults c NULL
with_defaults d NULL
with_defaults rowid unique_rowid()
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/logictest/testdata/logic_test/system
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@ descriptor BYTES true NULL · {primary} false
query TTBTTTB
SHOW COLUMNS FROM system.users
----
username STRING false NULL · {primary,users_user_id_idx} false
hashedPassword BYTES true NULL · {primary} false
isRole BOOL false f · {primary} false
user_id OID false NULL · {primary,users_user_id_idx} false
username STRING false NULL · {primary,users_user_id_idx} false
hashedPassword BYTES true NULL · {primary} false
isRole BOOL false false · {primary} false
user_id OID false NULL · {primary,users_user_id_idx} false

query TTBTTTB
SHOW COLUMNS FROM system.zones
Expand Down

0 comments on commit c97d4e6

Please sign in to comment.