Pavel Stehule <pavel.steh...@gmail.com> writes: > * some wrong in deparsing - doesn't support constraints > > postgres=# alter table a add column bbbsss int check (bbbsss > 0); > NOTICE: event: ddl_command_start, context: TOPLEVEL, tag: ALTER > TABLE, operation: ALTER, type: TABLE, schema: <NULL>, name: <NULL> > NOTICE: command: <NULL> > NOTICE: event: ddl_command_end, context: TOPLEVEL, tag: ALTER TABLE, > operation: ALTER, type: TABLE, schema: public, name: a > NOTICE: command: ALTER TABLE public.a ADD COLUMN bbbsss pg_catalog.int4, ; > ALTER TABLE
So apparently to be able to decipher what ALTER TABLE did actually do you need more than just hook yourself after transformAlterTableStmt() have been done, because the interesting stuff is happening in the alter table "work queue", see ATController in src/backend/commands/tablecmds.c for details. Exporting that data, I'm now able to implement constraint rewriting this way: alter table a add column bbbsss int check (bbbsss > 0); NOTICE: AT_AddConstraint: a_bbbsss_check NOTICE: event: ddl_command_end, context: TOPLEVEL, tag: ALTER TABLE, operation: ALTER, type: TABLE, schema: public, name: a NOTICE: command: ALTER TABLE public.a ADD COLUMN bbbsss pg_catalog.int4, ADD CONSTRAINT a_bbbsss_check CHECK ((bbbsss > 0)); ALTER TABLE I did publish that work on the github repository (that I rebase every time I'm pulling from master, beware): https://github.com/dimitri/postgres/compare/evt_add_info This implementation also shows to me that it's not possible to get the command string from the parsetree directly nor after the DDL transform step if you want such things as the constraint name that's been produced automatically by the backend. And I don't see any way to implement that from an extension, without first patching the backend. As that's the kind of code we want to be able to break at will in between releases (or to fix an important bug in a minor update), I think we need to have the facility to provide users with the normalized command string in core. Regards, -- Dimitri Fontaine http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers