Skip to content

Commit

Permalink
sql: support backslash_quote session setting
Browse files Browse the repository at this point in the history
This setting is based on an previous issue: cockroachdb#45774. This commit set a placeholder for PostgreSQL configuration setting called (backslash_quote)[https://www.postgresql.org/docs/12/runtime-config-compatible.html#GUC-BACKSLASH-QUOTE], and ensured it is compatible with ORMS.

When users try setting the backslash_quote session variable, CRDB will let it pass, but not making any changes. We leave the functionality implementation to future works.

Details:
- Added `backslash_quote` at varGen at `sql/vars.go` without implementing the true functionality

- Tested it with `subtest backslash_quote_test` at `pkg/sql/logictest/testdata/logic_test/set`

- Removed `backslash_quote` from `unsupported_vars.go`

Updates:

- nil: updated url for backslash_quote, and removed extra spaces

- Deleted `backslash_quote` from `unsupported_vars.go`

- Added `./.idea` at `.gitignore`

- Ran `make testlogic FILES="variables show_source pg_catalog" TESTFLAGS=-rewrite` but with the error: `E210708 03:58:33.948439 1281 sql/conn_executor.go:950  [n1,client=127.0.0.1:64106,hostssl,user=root] 1  error deleting temporary objects at session close, the temp tables deletion job will retry periodically: failed to send RPC: sending to all replicas failed; last error: node unavailable; try another peer`
  • Loading branch information
ZhouXing19 committed Jul 8, 2021
1 parent 78b15bf commit bcbc487
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ build/Railroad.jar

# Per-user .bazelrc
/.bazelrc.user

# Local .idea
/.idea
3 changes: 3 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/pg_catalog
Original file line number Diff line number Diff line change
Expand Up @@ -3394,6 +3394,7 @@ WHERE
----
name setting category short_desc extra_desc vartype
application_name · NULL NULL NULL string
backslash_quote safe_encoding NULL NULL NULL string
bytea_output hex NULL NULL NULL string
client_encoding UTF8 NULL NULL NULL string
client_min_messages notice NULL NULL NULL string
Expand Down Expand Up @@ -3476,6 +3477,7 @@ WHERE
----
name setting unit context enumvals boot_val reset_val
application_name · NULL user NULL · ·
backslash_quote safe_encoding NULL user NULL safe_encoding safe_encoding
bytea_output hex NULL user NULL hex hex
client_encoding UTF8 NULL user NULL UTF8 UTF8
client_min_messages notice NULL user NULL notice notice
Expand Down Expand Up @@ -3553,6 +3555,7 @@ SELECT name, source, min_val, max_val, sourcefile, sourceline FROM pg_catalog.pg
----
name source min_val max_val sourcefile sourceline
application_name NULL NULL NULL NULL NULL
backslash_quote NULL NULL NULL NULL NULL
bytea_output NULL NULL NULL NULL NULL
client_encoding NULL NULL NULL NULL NULL
client_min_messages NULL NULL NULL NULL NULL
Expand Down
14 changes: 14 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/set
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,17 @@ SET standard_conforming_strings='true'

statement ok
SET standard_conforming_strings='on'

subtest backslash_quote_test

statement ok
SET backslash_quote = 'on';

statement ok
SET backslash_quote = 'off';

statement ok
SET backslash_quote = 'safe_encoding';

statement error invalid value for parameter "backslash_quote"
SET backslash_quote = '123';
1 change: 1 addition & 0 deletions pkg/sql/logictest/testdata/logic_test/show_source
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ WHERE variable != 'optimizer' AND variable != 'crdb_version' AND variable != 'se
----
variable value
application_name ·
backslash_quote safe_encoding
bytea_output hex
client_encoding UTF8
client_min_messages notice
Expand Down
1 change: 0 additions & 1 deletion pkg/sql/unsupported_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ var UnsupportedVars = func(ss ...string) map[string]struct{} {
// "application_name",
"array_nulls",
"backend_flush_after",
"backslash_quote",
// "bytea_output",
"check_function_bodies",
// "client_encoding",
Expand Down
5 changes: 4 additions & 1 deletion pkg/sql/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,11 @@ var varGen = map[string]sessionVar{
// See https://www.postgresql.org/docs/10/static/runtime-config-client.html#GUC-LOC-TIMEOUT
`lock_timeout`: makeCompatIntVar(`lock_timeout`, 0),

// See https://www.postgresql.org/docs/13/runtime-config-compatible.html
`backslash_quote`: makeCompatStringVar(`backslash_quote`, `safe_encoding`, `on`, `off`, `safe_encoding`),

// Supported for PG compatibility only.
// See https://www.postgresql.org/docs/10/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
// See https://www.postgresql.org/docs/10/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIER
`max_identifier_length`: {
Get: func(evalCtx *extendedEvalContext) string { return "128" },
},
Expand Down

0 comments on commit bcbc487

Please sign in to comment.