Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using backslash in SQL string literals #7669

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/backend/columnar/sql/citus_columnar--11.1-1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ BEGIN
-- from version 12 and up we have support for tableam's if installed on pg11 we can't
-- create the objects here. Instead we rely on citus_finish_pg_upgrade to be called by the
-- user instead to add the missing objects
IF substring(current_Setting('server_version'), '\d+')::int >= 12 THEN
IF substring(current_Setting('server_version'), '[0-9]+')::int >= 12 THEN
EXECUTE $$
--#include "udfs/columnar_handler/10.0-1.sql"
CREATE OR REPLACE FUNCTION columnar.columnar_handler(internal)
Expand Down
2 changes: 1 addition & 1 deletion src/backend/columnar/sql/columnar--10.0-3--10.1-1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-- Postgres assigns different names to those foreign keys in PG11, so act accordingly.
DO $proc$
BEGIN
IF substring(current_Setting('server_version'), '\d+')::int >= 12 THEN
IF substring(current_Setting('server_version'), '[0-9]+')::int >= 12 THEN
EXECUTE $$
ALTER TABLE columnar.chunk DROP CONSTRAINT chunk_storage_id_stripe_num_chunk_group_num_fkey;
ALTER TABLE columnar.chunk_group DROP CONSTRAINT chunk_group_storage_id_stripe_num_fkey;
Expand Down
2 changes: 1 addition & 1 deletion src/backend/columnar/sql/columnar--9.5-1--10.0-1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ BEGIN
-- from version 12 and up we have support for tableam's if installed on pg11 we can't
-- create the objects here. Instead we rely on citus_finish_pg_upgrade to be called by the
-- user instead to add the missing objects
IF substring(current_Setting('server_version'), '\d+')::int >= 12 THEN
IF substring(current_Setting('server_version'), '[0-9]+')::int >= 12 THEN
EXECUTE $$
#include "udfs/columnar_handler/10.0-1.sql"
#include "udfs/alter_columnar_table_set/10.0-1.sql"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SET search_path TO columnar;
DO $proc$
BEGIN

IF substring(current_Setting('server_version'), '\d+')::int >= 12 THEN
IF substring(current_Setting('server_version'), '[0-9]+')::int >= 12 THEN
EXECUTE $$
DROP FUNCTION pg_catalog.alter_columnar_table_reset(
table_name regclass,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ BEGIN

-- when postgres is version 12 or above we need to create the tableam. If the tableam
-- exist we assume all objects have been created.
IF substring(current_Setting('server_version'), '\d+')::int >= 12 THEN
IF substring(current_Setting('server_version'), '[0-9]+')::int >= 12 THEN
IF NOT EXISTS (SELECT 1 FROM pg_am WHERE amname = 'columnar') THEN

#include "../columnar_handler/10.0-1.sql"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ BEGIN

-- when postgres is version 12 or above we need to create the tableam. If the tableam
-- exist we assume all objects have been created.
IF substring(current_Setting('server_version'), '\d+')::int >= 12 THEN
IF substring(current_Setting('server_version'), '[0-9]+')::int >= 12 THEN
IF NOT EXISTS (SELECT 1 FROM pg_am WHERE amname = 'columnar') THEN

#include "../columnar_handler/10.0-1.sql"
Expand Down
2 changes: 1 addition & 1 deletion src/backend/distributed/sql/citus--8.0-1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ CREATE TRIGGER dist_shard_cache_invalidate

DO $proc$
BEGIN
IF substring(current_Setting('server_version'), '\d+')::int >= 14 THEN
IF substring(current_Setting('server_version'), '[0-9]+')::int >= 14 THEN
EXECUTE $$
CREATE AGGREGATE array_cat_agg(anycompatiblearray) (SFUNC = array_cat, STYPE = anycompatiblearray);
COMMENT ON AGGREGATE array_cat_agg(anycompatiblearray)
Expand Down
2 changes: 1 addition & 1 deletion src/backend/distributed/sql/udfs/any_value/9.1-1.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/backend/distributed/sql/udfs/any_value/latest.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DO $proc$
BEGIN
-- PG16 has its own any_value, so only create it pre PG16.
IF substring(current_Setting('server_version'), '\d+')::int < 16 THEN
IF substring(current_Setting('server_version'), '[0-9]+')::int < 16 THEN
EXECUTE $$

CREATE OR REPLACE FUNCTION pg_catalog.any_value_agg ( anyelement, anyelement )
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ BEGIN
FROM pg_dist_node_metadata;

SELECT r[1], r[2], r[3]
FROM regexp_matches(last_upgrade_version_string,'([0-9]+)\.([0-9]+)-([0-9]+)','') r
FROM regexp_matches(last_upgrade_version_string,'([0-9]+)[.]([0-9]+)-([0-9]+)','') r
INTO last_upgrade_major_version, last_upgrade_minor_version, last_upgrade_sqlpatch_version;

IF last_upgrade_major_version IS NULL OR last_upgrade_minor_version IS NULL OR last_upgrade_sqlpatch_version IS NULL THEN
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ DECLARE
BEGIN


IF substring(current_Setting('server_version'), '\d+')::int >= 14 THEN
IF substring(current_Setting('server_version'), '[0-9]+')::int >= 14 THEN
EXECUTE $cmd$
-- disable propagation to prevent EnsureCoordinator errors
-- the aggregate created here does not depend on Citus extension (yet)
Expand Down Expand Up @@ -53,7 +53,7 @@ BEGIN

-- PG16 has its own any_value, so only create it pre PG16.
-- We can remove this part when we drop support for PG16
IF substring(current_Setting('server_version'), '\d+')::int < 16 THEN
IF substring(current_Setting('server_version'), '[0-9]+')::int < 16 THEN
EXECUTE $cmd$
-- disable propagation to prevent EnsureCoordinator errors
-- the aggregate created here does not depend on Citus extension (yet)
Expand Down
2 changes: 1 addition & 1 deletion src/backend/distributed/sql/udfs/citus_shards/10.1-1.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/backend/distributed/sql/udfs/citus_shards/11.1-1.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/backend/distributed/transaction/transaction_recovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ PendingWorkerTransactionList(MultiConnection *connection)
int32 coordinatorId = GetLocalGroupId();

appendStringInfo(command, "SELECT gid FROM pg_prepared_xacts "
"WHERE gid LIKE 'citus\\_%d\\_%%' and database = current_database()",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea why %% is used here? Wouldn't % do the same? We could fix it while we are here

"WHERE gid LIKE 'citus/_%d/_%%' ESCAPE '/' and database = current_database()",
coordinatorId);

int querySent = SendRemoteCommand(connection, command->data);
Expand Down
Loading