Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
72109: sql: add compat support for LC_* session vars r=otan a=rafiss

fixes cockroachdb#72107

I'd like to backport this since these are read-only and it enhances tool
compat for a use case we want to support.

Release note (sql change): The session variables LC_COLLATE, LC_CTYPE,
LC_MESSAGES, LC_MONETARY, LC_NUMERIC, and LC_TIME were added for
compatibility with PostgreSQL. They only support the C.UTF-8 locale.

Co-authored-by: Rafi Shamim <[email protected]>
  • Loading branch information
craig[bot] and rafiss committed Oct 29, 2021
2 parents f6caf2d + 81d8abe commit b7dceca
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,8 @@ session_var ::=
| 'NAMES'
| 'ROLE'
| 'SESSION_USER'
| 'LC_COLLATE'
| 'LC_CTYPE'
| 'TIME' 'ZONE'

var_name ::=
Expand Down
6 changes: 6 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/information_schema
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/pg_catalog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
60 changes: 60 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/set
Original file line number Diff line number Diff line change
Expand Up @@ -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'
6 changes: 6 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/show_source
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -4978,16 +4978,18 @@ 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.
// See https://www.postgresql.org/docs/9.6/static/multibyte.html#AEN39236
| 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
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/unsupported_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
31 changes: 31 additions & 0 deletions pkg/sql/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b7dceca

Please sign in to comment.