Skip to content

Commit bbea230

Browse files
authored
Merge pull request #147 from launchql/fix/comments-quotes
Fix/comments quotes
2 parents c9f389e + f54ffa4 commit bbea230

File tree

6 files changed

+71
-1
lines changed

6 files changed

+71
-1
lines changed

TESTS.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Test Results
2+
3+
## Deparser Tests
4+
5+
**254/254 tests passing (100%)**
6+
7+
All deparser tests are now passing successfully, including the PostgreSQL 17 features:
8+
- GENERATED BY DEFAULT AS IDENTITY columns
9+
- UNIQUE NULLS NOT DISTINCT constraints
10+
11+
The deparser has been updated to properly handle these new PostgreSQL 17 syntax features.

__fixtures__/generated/generated.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21084,6 +21084,13 @@
2108421084
"misc/launchql-ext-default-roles-1.sql": "DO $$\n BEGIN\n IF NOT EXISTS (\n SELECT\n 1\n FROM\n pg_roles\n WHERE\n rolname = 'anonymous') THEN\n CREATE ROLE anonymous;\n COMMENT ON ROLE anonymous IS 'Anonymous group';\n ALTER USER anonymous WITH NOCREATEDB;\n ALTER USER anonymous WITH NOCREATEROLE;\n ALTER USER anonymous WITH NOLOGIN;\n ALTER USER anonymous WITH NOBYPASSRLS;\nEND IF;\nEND $$",
2108521085
"misc/launchql-ext-default-roles-2.sql": "DO $$\n BEGIN\n IF NOT EXISTS (\n SELECT\n 1\n FROM\n pg_roles\n WHERE\n rolname = 'authenticated') THEN\n CREATE ROLE authenticated;\n COMMENT ON ROLE authenticated IS 'Authenticated group';\n ALTER USER authenticated WITH NOCREATEDB;\n ALTER USER authenticated WITH NOCREATEROLE;\n ALTER USER authenticated WITH NOLOGIN;\n ALTER USER authenticated WITH NOBYPASSRLS;\nEND IF;\nEND $$",
2108621086
"misc/launchql-ext-default-roles-3.sql": "DO $$\n BEGIN\n IF NOT EXISTS (\n SELECT\n 1\n FROM\n pg_roles\n WHERE\n rolname = 'administrator') THEN\n CREATE ROLE administrator;\n COMMENT ON ROLE administrator IS 'Administration group';\n ALTER USER administrator WITH NOCREATEDB;\n ALTER USER administrator WITH NOCREATEROLE;\n ALTER USER administrator WITH NOLOGIN;\n ALTER USER administrator WITH BYPASSRLS;\n GRANT anonymous TO administrator;\n GRANT authenticated TO administrator;\nEND IF;\nEND $$",
21087+
"misc/issues-1.sql": "select from test_table WHERE status = 'complete'::text",
21088+
"misc/issues-2.sql": "select from test_table WHERE status = 'complete'",
21089+
"misc/issues-3.sql": "CREATE TABLE new_style (\n id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,\n val1 TEXT NOT NULL,\n val2 TEXT NULL,\n CONSTRAINT uq_val1_val2_new UNIQUE NULLS NOT DISTINCT (val1, val2)\n)",
21090+
"misc/issues-4.sql": "CREATE TABLE new_style (\n id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,\n val1 TEXT NOT NULL,\n val2 TEXT NULL\n)",
21091+
"misc/issues-5.sql": "ALTER TABLE new_style ADD CONSTRAINT uq_val1_val2_new UNIQUE NULLS NOT DISTINCT (val1, val2)",
21092+
"misc/issues-6.sql": "INSERT INTO\n public.people (id, name, epithet, is_great, gender, type_id, date_of_birth, date_of_death, place_of_birth, place_of_death, biography, canonical_status_id, image_url, source_url)\nVALUES\n (1, 'Asterius', 'of Amasea', FALSE, 'M', 1, '0350-01-01', '0410-01-01', 'Cappadocia', 'Amasea', NULL, 1, NULL, NULL),\n (2, 'Ausonius', NULL, FALSE, 'M', 1, '0310-01-01', '0395-01-01', 'Burdigala', NULL, NULL, NULL, NULL, NULL)\nON CONFLICT DO NOTHING",
21093+
"misc/issues-7.sql": "COMMENT ON COLUMN \"foo\".\"whatever\" IS $$\nSomething blah, this data may have chars like '\\n' and '\\r' in it.\n$$",
2108721094
"misc/inflection-1.sql": "CREATE SCHEMA inflection",
2108821095
"misc/inflection-2.sql": "GRANT USAGE ON SCHEMA inflection TO PUBLIC",
2108921096
"misc/inflection-3.sql": "ALTER DEFAULT PRIVILEGES IN SCHEMA inflection \n GRANT EXECUTE ON FUNCTIONS TO PUBLIC",
@@ -21150,6 +21157,7 @@
2115021157
"misc/cascades-25.sql": "ALTER TABLE some_table DROP CONSTRAINT some_constraint CASCADE",
2115121158
"misc/booleans-cast-1.sql": "SELECT * FROM myschema.mytable WHERE a = TRUE",
2115221159
"misc/booleans-cast-2.sql": "SELECT * FROM myschema.mytable WHERE a = CAST('t' AS boolean)",
21160+
"misc/booleans-cast-3.sql": "SELECT * FROM myschema.mytable WHERE a = 't'::boolean",
2115321161
"latest/postgres/create_view-1.sql": "CREATE FUNCTION interpt_pp(path, path)\n RETURNS point\n AS 'regresslib'\n LANGUAGE C STRICT",
2115421162
"latest/postgres/create_view-2.sql": "CREATE TABLE real_city (\n\tpop\t\t\tint4,\n\tcname\t\ttext,\n\toutline \tpath\n)",
2115521163
"latest/postgres/create_view-3.sql": "COPY real_city FROM 'filename'",
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
-- https://github.com/launchql/pgsql-parser/issues/131
2+
select from test_table WHERE status = 'complete'::text;
3+
select from test_table WHERE status = 'complete';
4+
5+
-- https://github.com/supabase/supabase/issues/13267
6+
CREATE TABLE new_style (
7+
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
8+
val1 TEXT NOT NULL,
9+
val2 TEXT NULL,
10+
CONSTRAINT uq_val1_val2_new UNIQUE NULLS NOT DISTINCT (val1, val2)
11+
);
12+
13+
-- https://github.com/supabase/supabase/issues/13267
14+
CREATE TABLE new_style (
15+
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
16+
val1 TEXT NOT NULL,
17+
val2 TEXT NULL
18+
);
19+
ALTER TABLE new_style ADD CONSTRAINT uq_val1_val2_new UNIQUE NULLS NOT DISTINCT (val1, val2);
20+
21+
-- https://github.com/launchql/pgsql-parser/issues/128
22+
INSERT INTO
23+
public.people (id, name, epithet, is_great, gender, type_id, date_of_birth, date_of_death, place_of_birth, place_of_death, biography, canonical_status_id, image_url, source_url)
24+
VALUES
25+
(1, 'Asterius', 'of Amasea', FALSE, 'M', 1, '0350-01-01', '0410-01-01', 'Cappadocia', 'Amasea', NULL, 1, NULL, NULL),
26+
(2, 'Ausonius', NULL, FALSE, 'M', 1, '0310-01-01', '0395-01-01', 'Burdigala', NULL, NULL, NULL, NULL, NULL)
27+
ON CONFLICT DO NOTHING;
28+
29+
-- https://github.com/launchql/pgsql-parser/issues/124
30+
COMMENT ON COLUMN "foo"."whatever" IS $$
31+
Something blah, this data may have chars like '\n' and '\r' in it.
32+
$$;

packages/deparser/__tests__/kitchen-sink/misc-booleans-cast.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const fixtures = new FixtureTestUtils();
55
it('misc-booleans-cast', async () => {
66
await fixtures.runFixtureTests([
77
"misc/booleans-cast-1.sql",
8-
"misc/booleans-cast-2.sql"
8+
"misc/booleans-cast-2.sql",
9+
"misc/booleans-cast-3.sql"
910
]);
1011
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
import { FixtureTestUtils } from '../../test-utils';
3+
const fixtures = new FixtureTestUtils();
4+
5+
it('misc-issues', async () => {
6+
await fixtures.runFixtureTests([
7+
"misc/issues-1.sql",
8+
"misc/issues-2.sql",
9+
"misc/issues-3.sql",
10+
"misc/issues-4.sql",
11+
"misc/issues-5.sql",
12+
"misc/issues-6.sql",
13+
"misc/issues-7.sql"
14+
]);
15+
});

packages/deparser/src/deparser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,6 +2356,9 @@ export class Deparser implements DeparserVisitor {
23562356
break;
23572357
case 'CONSTR_UNIQUE':
23582358
output.push('UNIQUE');
2359+
if (node.nulls_not_distinct) {
2360+
output.push('NULLS NOT DISTINCT');
2361+
}
23592362
if (node.keys && node.keys.length > 0) {
23602363
const keyList = ListUtils.unwrapList(node.keys)
23612364
.map(key => this.visit(key, context))

0 commit comments

Comments
 (0)