Open
Description
Hi,
In deparser
, foreign constraints' name should be quoted as others constraints' name.
SELECT deparser.expression(ast.alter_table_stmt(
v_relation := ast_helpers.range_var(
v_schemaname := 'public',
v_relname := 't1'
),
v_relkind := 'OBJECT_TABLE',
v_cmds := to_jsonb(ARRAY[
ast.alter_table_cmd(
v_subtype := 'AT_AddConstraint',
v_def := ast.constraint(
v_conname := 'my-foreign-key',
v_contype := 'CONSTR_FOREIGN',
v_pktable := ast_helpers.range_var(
v_schemaname := 'public',
v_relname := 'ref_t1'
),
v_pk_attrs := to_jsonb(ARRAY[
ast.string('id')
]),
v_fk_attrs := to_jsonb(ARRAY[
ast.string('id')
])
)
)
])
));
expression
------------------------------------------------------------------------------------------------------
ALTER TABLE public.t1 ADD CONSTRAINT "my-foreign-key" FOREIGN KEY (id) REFERENCES public.ref_t1 (id)
(1 row)
However, libpg_query
seems to ignore this rule (static void deparseConstraint) and tests are not successful in kitchen-sink.test.js
on sqlfromparser
step.
expect(cleanLines(sql)).toMatchSnapshot();
expect(cleanLines(sqlfromparser)).toMatchSnapshot(); /* <-- HERE */
Summary of all failing tests
FAIL test/__tests__/kitchen-sink.test.js (8.552 s)
● kitchen sink › alter
expect(received).toMatchSnapshot()
Snapshot name: `kitchen sink alter 2`
- Snapshot - 1
+ Received + 1
- ALTER TABLE scha.foo ADD CONSTRAINT "MyConstraintKey" FOREIGN KEY ( order_id ) REFERENCES othr.orders ( id );
+ ALTER TABLE scha.foo ADD CONSTRAINT MyConstraintKey FOREIGN KEY ( order_id ) REFERENCES othr.orders ( id );
Should I open a new issue in pgsql-parser
and/or libpg_query
?
Regards
Metadata
Metadata
Assignees
Labels
No labels