Skip to content

Commit

Permalink
Adds rules option to CREATE COLLATION
Browse files Browse the repository at this point in the history
Relevant PG commit:
postgres/postgres@30a53b7
30a53b7
  • Loading branch information
naisila committed Sep 6, 2023
1 parent 5c658b4 commit a32f744
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/backend/distributed/commands/collation.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,16 @@ CreateCollationDDLInternal(Oid collationId, Oid *collowner, char **quotedCollati
pfree(collcollate);
pfree(collctype);
#endif

#if PG_VERSION_NUM >= PG_VERSION_16
char *collicurules = NULL;
datum = SysCacheGetAttr(COLLOID, heapTuple, Anum_pg_collation_collicurules, &isnull);
if (!isnull)
{
collicurules = TextDatumGetCString(datum);
appendStringInfo(&collationNameDef, ", rules = %s",
quote_literal_cstr(collicurules));
}
#endif
if (!collisdeterministic)
{
appendStringInfoString(&collationNameDef, ", deterministic = false");
Expand Down
84 changes: 84 additions & 0 deletions src/test/regress/expected/pg16.out
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,90 @@ SELECT result FROM run_command_on_workers
DROP DATABASE
(2 rows)

SET search_path TO pg16;
-- New rules option added to CREATE COLLATION
-- Similar to above test with CREATE DATABASE
-- Relevant PG commit:
-- https://github.com/postgres/postgres/commit/30a53b7
CREATE COLLATION default_rule (provider = icu, locale = '');
NOTICE: using standard form "und" for ICU locale ""
CREATE COLLATION special_rule (provider = icu, locale = '', rules = '&a < g');
NOTICE: using standard form "und" for ICU locale ""
CREATE TABLE test_collation_rules (a text);
SELECT create_distributed_table('test_collation_rules', 'a');
create_distributed_table
---------------------------------------------------------------------

(1 row)

INSERT INTO test_collation_rules VALUES ('Abernathy'), ('apple'), ('bird'), ('Boston'), ('Graham'), ('green');
SELECT collname, collprovider, colliculocale, collicurules
FROM pg_collation
WHERE collname like '%_rule%'
ORDER BY 1;
collname | collprovider | colliculocale | collicurules
---------------------------------------------------------------------
default_rule | i | und |
special_rule | i | und | &a < g
(2 rows)

SELECT * FROM test_collation_rules ORDER BY a COLLATE default_rule;
a
---------------------------------------------------------------------
Abernathy
apple
bird
Boston
Graham
green
(6 rows)

SELECT * FROM test_collation_rules ORDER BY a COLLATE special_rule;
a
---------------------------------------------------------------------
Abernathy
apple
green
bird
Boston
Graham
(6 rows)

\c - - - :worker_1_port
SET search_path TO pg16;
SELECT collname, collprovider, colliculocale, collicurules
FROM pg_collation
WHERE collname like '%_rule%'
ORDER BY 1;
collname | collprovider | colliculocale | collicurules
---------------------------------------------------------------------
default_rule | i | und |
special_rule | i | und | &a < g
(2 rows)

SELECT * FROM test_collation_rules ORDER BY a COLLATE default_rule;
a
---------------------------------------------------------------------
Abernathy
apple
bird
Boston
Graham
green
(6 rows)

SELECT * FROM test_collation_rules ORDER BY a COLLATE special_rule;
a
---------------------------------------------------------------------
Abernathy
apple
green
bird
Boston
Graham
(6 rows)

\c - - - :master_port
SET search_path TO pg16;
SET citus.next_shard_id TO 951000;
-- Foreign table TRUNCATE trigger
Expand Down
34 changes: 34 additions & 0 deletions src/test/regress/sql/pg16.sql
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,40 @@ DROP DATABASE test_db;
SELECT result FROM run_command_on_workers
($$DROP DATABASE test_db$$);
SET search_path TO pg16;

-- New rules option added to CREATE COLLATION
-- Similar to above test with CREATE DATABASE
-- Relevant PG commit:
-- https://github.com/postgres/postgres/commit/30a53b7

CREATE COLLATION default_rule (provider = icu, locale = '');
CREATE COLLATION special_rule (provider = icu, locale = '', rules = '&a < g');

CREATE TABLE test_collation_rules (a text);
SELECT create_distributed_table('test_collation_rules', 'a');
INSERT INTO test_collation_rules VALUES ('Abernathy'), ('apple'), ('bird'), ('Boston'), ('Graham'), ('green');

SELECT collname, collprovider, colliculocale, collicurules
FROM pg_collation
WHERE collname like '%_rule%'
ORDER BY 1;

SELECT * FROM test_collation_rules ORDER BY a COLLATE default_rule;
SELECT * FROM test_collation_rules ORDER BY a COLLATE special_rule;

\c - - - :worker_1_port
SET search_path TO pg16;

SELECT collname, collprovider, colliculocale, collicurules
FROM pg_collation
WHERE collname like '%_rule%'
ORDER BY 1;

SELECT * FROM test_collation_rules ORDER BY a COLLATE default_rule;
SELECT * FROM test_collation_rules ORDER BY a COLLATE special_rule;

\c - - - :master_port
SET search_path TO pg16;
SET citus.next_shard_id TO 951000;

-- Foreign table TRUNCATE trigger
Expand Down

0 comments on commit a32f744

Please sign in to comment.