diff --git a/docs/generated/sql/bnf/stmt_block.bnf b/docs/generated/sql/bnf/stmt_block.bnf index d6065ff85b72..3f5edfba22f9 100644 --- a/docs/generated/sql/bnf/stmt_block.bnf +++ b/docs/generated/sql/bnf/stmt_block.bnf @@ -1561,6 +1561,8 @@ session_var ::= | 'NAMES' | 'ROLE' | 'SESSION_USER' + | 'LC_COLLATE' + | 'LC_CTYPE' | 'TIME' 'ZONE' var_name ::= diff --git a/pkg/sql/logictest/testdata/logic_test/information_schema b/pkg/sql/logictest/testdata/logic_test/information_schema index 9b34ba712481..6dc765c47a9e 100644 --- a/pkg/sql/logictest/testdata/logic_test/information_schema +++ b/pkg/sql/logictest/testdata/logic_test/information_schema @@ -4656,6 +4656,12 @@ intervalstyle postgres intervalstyle_enabled off is_superuser on large_full_scan_rows 1000 +lc_collate C.UTF-8 +lc_ctype C.UTF-8 +lc_messages C.UTF-8 +lc_monetary C.UTF-8 +lc_numeric C.UTF-8 +lc_time C.UTF-8 locality region=test,dc=dc1 locality_optimized_partitioned_index_scan on lock_timeout 0 diff --git a/pkg/sql/logictest/testdata/logic_test/pg_catalog b/pkg/sql/logictest/testdata/logic_test/pg_catalog index b1ba416e62de..b2598cf6839c 100644 --- a/pkg/sql/logictest/testdata/logic_test/pg_catalog +++ b/pkg/sql/logictest/testdata/logic_test/pg_catalog @@ -4038,6 +4038,12 @@ intervalstyle postgres NULL intervalstyle_enabled off NULL NULL NULL string is_superuser on NULL NULL NULL string large_full_scan_rows 1000 NULL NULL NULL string +lc_collate C.UTF-8 NULL NULL NULL string +lc_ctype C.UTF-8 NULL NULL NULL string +lc_messages C.UTF-8 NULL NULL NULL string +lc_monetary C.UTF-8 NULL NULL NULL string +lc_numeric C.UTF-8 NULL NULL NULL string +lc_time C.UTF-8 NULL NULL NULL string locality region=test,dc=dc1 NULL NULL NULL string locality_optimized_partitioned_index_scan on NULL NULL NULL string lock_timeout 0 NULL NULL NULL string @@ -4136,6 +4142,12 @@ intervalstyle postgres NULL intervalstyle_enabled off NULL user NULL off off is_superuser on NULL user NULL on on large_full_scan_rows 1000 NULL user NULL 1000 1000 +lc_collate C.UTF-8 NULL user NULL C.UTF-8 C.UTF-8 +lc_ctype C.UTF-8 NULL user NULL C.UTF-8 C.UTF-8 +lc_messages C.UTF-8 NULL user NULL C.UTF-8 C.UTF-8 +lc_monetary C.UTF-8 NULL user NULL C.UTF-8 C.UTF-8 +lc_numeric C.UTF-8 NULL user NULL C.UTF-8 C.UTF-8 +lc_time C.UTF-8 NULL user NULL C.UTF-8 C.UTF-8 locality region=test,dc=dc1 NULL user NULL region=test,dc=dc1 region=test,dc=dc1 locality_optimized_partitioned_index_scan on NULL user NULL on on lock_timeout 0 NULL user NULL 0s 0s @@ -4230,6 +4242,12 @@ intervalstyle NULL NULL NULL intervalstyle_enabled NULL NULL NULL NULL NULL is_superuser NULL NULL NULL NULL NULL large_full_scan_rows NULL NULL NULL NULL NULL +lc_collate NULL NULL NULL NULL NULL +lc_ctype NULL NULL NULL NULL NULL +lc_messages NULL NULL NULL NULL NULL +lc_monetary NULL NULL NULL NULL NULL +lc_numeric NULL NULL NULL NULL NULL +lc_time NULL NULL NULL NULL NULL locality NULL NULL NULL NULL NULL locality_optimized_partitioned_index_scan NULL NULL NULL NULL NULL lock_timeout NULL NULL NULL NULL NULL diff --git a/pkg/sql/logictest/testdata/logic_test/set b/pkg/sql/logictest/testdata/logic_test/set index 70717b69af07..5aee32edcca9 100644 --- a/pkg/sql/logictest/testdata/logic_test/set +++ b/pkg/sql/logictest/testdata/logic_test/set @@ -566,3 +566,63 @@ SET disable_plan_gists = 'true' statement ok SET disable_plan_gists = 'false' + +query T +SHOW LC_COLLATE +---- +C.UTF-8 + +query T +SHOW LC_CTYPE +---- +C.UTF-8 + +query T +SHOW LC_MESSAGES +---- +C.UTF-8 + +query T +SHOW LC_MONETARY +---- +C.UTF-8 + +query T +SHOW LC_NUMERIC +---- +C.UTF-8 + +query T +SHOW LC_TIME +---- +C.UTF-8 + +statement error parameter "lc_collate" cannot be changed +SET LC_COLLATE = 'C.UTF-8' + +statement error parameter "lc_ctype" cannot be changed +SET LC_CTYPE = 'C.UTF-8' + +statement ok +SET LC_MESSAGES = 'C.UTF-8' + +statement ok +SET LC_MONETARY = 'C.UTF-8' + +statement ok +SET LC_NUMERIC = 'C.UTF-8' + +statement ok +SET LC_TIME = 'C.UTF-8' + +statement error invalid value for parameter "lc_messages": "en_US.UTF-8" +SET LC_MESSAGES = 'en_US.UTF-8' + +statement error invalid value for parameter "lc_monetary": "en_US.UTF-8" +SET LC_MONETARY = 'en_US.UTF-8' + +statement error invalid value for parameter "lc_numeric": "en_US.UTF-8" +SET LC_NUMERIC = 'en_US.UTF-8' + +statement error invalid value for parameter "lc_time": "en_US.UTF-8" +SET LC_TIME = 'en_US.UTF-8' diff --git a/pkg/sql/logictest/testdata/logic_test/show_source b/pkg/sql/logictest/testdata/logic_test/show_source index 9a88a187bb0f..3af3a22abe54 100644 --- a/pkg/sql/logictest/testdata/logic_test/show_source +++ b/pkg/sql/logictest/testdata/logic_test/show_source @@ -72,6 +72,12 @@ intervalstyle postgres intervalstyle_enabled off is_superuser on large_full_scan_rows 1000 +lc_collate C.UTF-8 +lc_ctype C.UTF-8 +lc_messages C.UTF-8 +lc_monetary C.UTF-8 +lc_numeric C.UTF-8 +lc_time C.UTF-8 locality region=test,dc=dc1 locality_optimized_partitioned_index_scan on lock_timeout 0 diff --git a/pkg/sql/parser/sql.y b/pkg/sql/parser/sql.y index f6873872e4ed..e2b14391ab3a 100644 --- a/pkg/sql/parser/sql.y +++ b/pkg/sql/parser/sql.y @@ -4978,9 +4978,9 @@ show_session_stmt: session_var: IDENT -// Although ALL, SESSION_USER and DATABASE are identifiers for the -// purpose of SHOW, they lex as separate token types, so they need -// separate rules. +// Although ALL, SESSION_USER, DATABASE, LC_COLLATE, and LC_CTYPE are +// identifiers for the purpose of SHOW, they lex as separate token types, so +// they need separate rules. | ALL | DATABASE // SET NAMES is standard SQL for SET client_encoding. @@ -4988,6 +4988,8 @@ session_var: | NAMES { $$ = "client_encoding" } | ROLE | SESSION_USER +| LC_COLLATE +| LC_CTYPE // TIME ZONE is special: it is two tokens, but is really the identifier "TIME ZONE". | TIME ZONE { $$ = "timezone" } | TIME error // SHOW HELP: SHOW SESSION diff --git a/pkg/sql/unsupported_vars.go b/pkg/sql/unsupported_vars.go index 3cfaa054d09e..51879d5e6ba2 100644 --- a/pkg/sql/unsupported_vars.go +++ b/pkg/sql/unsupported_vars.go @@ -118,10 +118,10 @@ var UnsupportedVars = func(ss ...string) map[string]struct{} { // "idle_in_transaction_session_timeout", "ignore_checksum_failure", "join_collapse_limit", - "lc_messages", - "lc_monetary", - "lc_numeric", - "lc_time", + // "lc_messages", + // "lc_monetary", + // "lc_numeric", + // "lc_time", "lo_compat_privileges", "local_preload_libraries", // "lock_timeout", diff --git a/pkg/sql/vars.go b/pkg/sql/vars.go index 7d797b45e52a..b3cc166c66b0 100644 --- a/pkg/sql/vars.go +++ b/pkg/sql/vars.go @@ -49,6 +49,11 @@ const ( PgServerVersion = "13.0.0" // PgServerVersionNum is the latest version of postgres that we claim to support in the numeric format of "server_version_num". PgServerVersionNum = "130000" + // PgCompatLocale is the locale string we advertise in `LC_*` session + // variables. C.UTF-8 is the only locale that is allowed in CREATE DATABASE + // at the time of writing. + // See https://www.postgresql.org/docs/14/locale.html + PgCompatLocale = "C.UTF-8" ) type getStringValFn = func( @@ -1123,6 +1128,32 @@ var varGen = map[string]sessionVar{ // See https://www.postgresql.org/docs/10/static/runtime-config-preset.html#GUC-SERVER-VERSION-NUM `server_version_num`: makeReadOnlyVar(PgServerVersionNum), + // This is read-only in Postgres also. + // See https://www.postgresql.org/docs/14/sql-show.html and + // https://www.postgresql.org/docs/14/locale.html + `lc_collate`: makeReadOnlyVar(PgCompatLocale), + + // This is read-only in Postgres also. + // See https://www.postgresql.org/docs/14/sql-show.html and + // https://www.postgresql.org/docs/14/locale.html + `lc_ctype`: makeReadOnlyVar(PgCompatLocale), + + // See https://www.postgresql.org/docs/14/sql-show.html and + // https://www.postgresql.org/docs/14/locale.html + `lc_messages`: makeCompatStringVar("lc_messages", PgCompatLocale), + + // See https://www.postgresql.org/docs/14/sql-show.html and + // https://www.postgresql.org/docs/14/locale.html + `lc_monetary`: makeCompatStringVar("lc_monetary", PgCompatLocale), + + // See https://www.postgresql.org/docs/14/sql-show.html and + // https://www.postgresql.org/docs/14/locale.html + `lc_numeric`: makeCompatStringVar("lc_numeric", PgCompatLocale), + + // See https://www.postgresql.org/docs/14/sql-show.html and + // https://www.postgresql.org/docs/14/locale.html + `lc_time`: makeCompatStringVar("lc_time", PgCompatLocale), + // See https://www.postgresql.org/docs/9.4/runtime-config-connection.html `ssl_renegotiation_limit`: { Hidden: true,