diff --git a/__fixtures__/generated/generated.json b/__fixtures__/generated/generated.json index a9ad7570..89dd5573 100644 --- a/__fixtures__/generated/generated.json +++ b/__fixtures__/generated/generated.json @@ -21256,6 +21256,14 @@ "misc/quotes_etc-28.sql": "DO $$\nBEGIN\n RAISE NOTICE 'Line one\\nLine two';\nEND;\n$$ LANGUAGE plpgsql", "misc/quotes_etc-29.sql": "CREATE USER MAPPING FOR local_user SERVER \"foreign_server\" OPTIONS (user 'remote_user', password 'secret123')", "misc/quotes_etc-30.sql": "CREATE USER MAPPING FOR local_user SERVER foreign_server OPTIONS (user 'remote_user', password 'secret123')", + "misc/qualified-like-and-refresh-1.sql": "CREATE TABLE t (LIKE p)", + "misc/qualified-like-and-refresh-2.sql": "CREATE TABLE t (LIKE s.p)", + "misc/qualified-like-and-refresh-3.sql": "CREATE TABLE t (LIKE s.p INCLUDING ALL)", + "misc/qualified-like-and-refresh-4.sql": "CREATE TABLE t (LIKE db.s.p INCLUDING DEFAULTS EXCLUDING INDEXES)", + "misc/qualified-like-and-refresh-5.sql": "CREATE TABLE s.t (id int, LIKE \"My Schema\".\"My Table\" INCLUDING DEFAULTS INCLUDING CONSTRAINTS)", + "misc/qualified-like-and-refresh-6.sql": "REFRESH MATERIALIZED VIEW mv", + "misc/qualified-like-and-refresh-7.sql": "REFRESH MATERIALIZED VIEW s.mv", + "misc/qualified-like-and-refresh-8.sql": "REFRESH MATERIALIZED VIEW CONCURRENTLY db.s.mv WITH NO DATA", "misc/pg_catalog-1.sql": "SELECT json_object('{}')", "misc/pg_catalog-2.sql": "SELECT * FROM generate_series(1, 5)", "misc/pg_catalog-3.sql": "SELECT get_byte(E'\\\\xDEADBEEF'::bytea, 1)", diff --git a/__fixtures__/kitchen-sink/misc/qualified-like-and-refresh.sql b/__fixtures__/kitchen-sink/misc/qualified-like-and-refresh.sql new file mode 100644 index 00000000..ebaf0a34 --- /dev/null +++ b/__fixtures__/kitchen-sink/misc/qualified-like-and-refresh.sql @@ -0,0 +1,9 @@ +-- CREATE TABLE ... (LIKE ...) and REFRESH MATERIALIZED VIEW keep schema/catalog-qualified relations +CREATE TABLE t (LIKE p); +CREATE TABLE t (LIKE s.p); +CREATE TABLE t (LIKE s.p INCLUDING ALL); +CREATE TABLE t (LIKE db.s.p INCLUDING DEFAULTS EXCLUDING INDEXES); +CREATE TABLE s.t (id int, LIKE "My Schema"."My Table" INCLUDING DEFAULTS INCLUDING CONSTRAINTS); +REFRESH MATERIALIZED VIEW mv; +REFRESH MATERIALIZED VIEW s.mv; +REFRESH MATERIALIZED VIEW CONCURRENTLY db.s.mv WITH NO DATA; diff --git a/packages/deparser/__tests__/kitchen-sink/misc-qualified-like-and-refresh.test.ts b/packages/deparser/__tests__/kitchen-sink/misc-qualified-like-and-refresh.test.ts new file mode 100644 index 00000000..62145dd1 --- /dev/null +++ b/packages/deparser/__tests__/kitchen-sink/misc-qualified-like-and-refresh.test.ts @@ -0,0 +1,16 @@ + +import { FixtureTestUtils } from '../../test-utils'; +const fixtures = new FixtureTestUtils(); + +it('misc-qualified-like-and-refresh', async () => { + await fixtures.runFixtureTests([ + "misc/qualified-like-and-refresh-1.sql", + "misc/qualified-like-and-refresh-2.sql", + "misc/qualified-like-and-refresh-3.sql", + "misc/qualified-like-and-refresh-4.sql", + "misc/qualified-like-and-refresh-5.sql", + "misc/qualified-like-and-refresh-6.sql", + "misc/qualified-like-and-refresh-7.sql", + "misc/qualified-like-and-refresh-8.sql" +]); +}); diff --git a/packages/deparser/src/deparser.ts b/packages/deparser/src/deparser.ts index 94c7f625..6c379b3d 100644 --- a/packages/deparser/src/deparser.ts +++ b/packages/deparser/src/deparser.ts @@ -10043,7 +10043,7 @@ export class Deparser implements DeparserVisitor { } if (node.relation) { - output.push(this.visit(node.relation as any, context)); + output.push(this.RangeVar(node.relation, context)); } if (node.skipData) { @@ -11664,7 +11664,7 @@ export class Deparser implements DeparserVisitor { const output: string[] = ['LIKE']; if (node.relation) { - output.push(this.visit(node.relation as any, context)); + output.push(this.RangeVar(node.relation, context)); } if (node.options && typeof node.options === 'number') {