\pset null _null_ \pset format unaligned SET client_min_messages = warning; SET ROLE postgres; select sql_kind, sql_identifier from ddlx_identify('ddlx_identify(oid)'::regprocedure); sql_kind|sql_identifier FUNCTION|ddlx_identify(oid) (1 row) create function trig() returns trigger as $$begin return old; end $$ language plpgsql; CREATE TABLE test_class_r ( a serial primary key, b text unique not null default e'Hello, world!\n', c timestamp without time zone check(c > '2001-01-01'), d timestamp with time zone, e numeric(30)[], f numeric(10,2)[], g varchar(10)[], h varchar[], v tsvector ); COMMENT ON TABLE test_class_r IS 'Comment1'; alter table test_class_r alter e set (n_distinct=10); alter table test_class_r alter f set (n_distinct=100); alter table test_class_r alter h set statistics 50; grant all on test_class_r to public; select sql_kind, sql_identifier from ddlx_identify('test_class_r'::regclass); sql_kind|sql_identifier TABLE|test_class_r (1 row) alter table test_class_r alter h set storage external; create trigger aaaa before update on test_class_r for each row when (old.* is distinct from new.*) execute procedure trig('AAAA'); alter table test_class_r disable trigger aaaa; create unique index idx1 on test_class_r (lower(b)) where b is not null; create index idx2 on test_class_r using gin (v); create index idx3 on test_class_r(g) with (fillfactor=50); cluster test_class_r using idx3; SELECT replace(ddlx_script('test_class_r'::regclass),'FUNCTION','PROCEDURE') as ddlx_script; ddlx_script BEGIN; /* ALTER TABLE test_class_r ALTER a DROP DEFAULT; ALTER TABLE test_class_r DROP CONSTRAINT test_class_r_c_check; DROP TABLE test_class_r; */ -- Type: TABLE ; Name: test_class_r; Owner: postgres CREATE TABLE test_class_r ( a integer NOT NULL, b text NOT NULL, c timestamp without time zone, d timestamp with time zone, e numeric(30,0)[], f numeric(10,2)[], g character varying(10)[], h character varying[], v tsvector ); COMMENT ON TABLE test_class_r IS 'Comment1'; ALTER TABLE test_class_r OWNER TO postgres; ALTER TABLE test_class_r ALTER b SET DEFAULT 'Hello, world! '::text; ALTER SEQUENCE test_class_r_a_seq OWNED BY test_class_r.a; ALTER TABLE test_class_r ALTER h SET STORAGE external; ALTER TABLE test_class_r ALTER e SET ( n_distinct = '10' ); ALTER TABLE test_class_r ALTER f SET ( n_distinct = '100' ); ALTER TABLE test_class_r ALTER h SET STATISTICS 50; ALTER TABLE test_class_r ADD CONSTRAINT test_class_r_b_key UNIQUE (b); ALTER TABLE test_class_r ADD CONSTRAINT test_class_r_pkey PRIMARY KEY (a); ALTER TABLE test_class_r ADD CONSTRAINT test_class_r_c_check CHECK (c > 'Mon Jan 01 00:00:00 2001'::timestamp without time zone); CREATE UNIQUE INDEX idx1 ON public.test_class_r USING btree (lower(b)) WHERE (b IS NOT NULL); CREATE INDEX idx2 ON public.test_class_r USING gin (v); CREATE INDEX idx3 ON public.test_class_r USING btree (g) WITH (fillfactor='50'); CLUSTER test_class_r USING idx3; CREATE TRIGGER aaaa BEFORE UPDATE ON test_class_r FOR EACH ROW WHEN (old.* IS DISTINCT FROM new.*) EXECUTE PROCEDURE trig('AAAA'); ALTER TABLE test_class_r DISABLE TRIGGER aaaa; GRANT INSERT ON test_class_r TO PUBLIC; GRANT SELECT ON test_class_r TO PUBLIC; GRANT UPDATE ON test_class_r TO PUBLIC; GRANT DELETE ON test_class_r TO PUBLIC; GRANT TRUNCATE ON test_class_r TO PUBLIC; GRANT REFERENCES ON test_class_r TO PUBLIC; GRANT TRIGGER ON test_class_r TO PUBLIC; -- DEPENDANTS ALTER TABLE test_class_r ADD CONSTRAINT test_class_r_c_check CHECK (c > 'Mon Jan 01 00:00:00 2001'::timestamp without time zone); ALTER TABLE test_class_r ALTER a SET DEFAULT nextval('test_class_r_a_seq'::regclass); END; (1 row) cluster test_class_r using test_class_r_pkey; SELECT replace(ddlx_script('test_class_r'::regtype),'FUNCTION','PROCEDURE') as ddlx_script; ddlx_script BEGIN; /* DROP TABLE test_class_r; */ -- Type: TABLE ; Name: test_class_r; Owner: postgres CREATE TABLE test_class_r ( a integer NOT NULL, b text NOT NULL, c timestamp without time zone, d timestamp with time zone, e numeric(30,0)[], f numeric(10,2)[], g character varying(10)[], h character varying[], v tsvector ); COMMENT ON TABLE test_class_r IS 'Comment1'; ALTER TABLE test_class_r OWNER TO postgres; ALTER TABLE test_class_r ALTER b SET DEFAULT 'Hello, world! '::text; ALTER SEQUENCE test_class_r_a_seq OWNED BY test_class_r.a; ALTER TABLE test_class_r ALTER h SET STORAGE external; ALTER TABLE test_class_r ALTER e SET ( n_distinct = '10' ); ALTER TABLE test_class_r ALTER f SET ( n_distinct = '100' ); ALTER TABLE test_class_r ALTER h SET STATISTICS 50; ALTER TABLE test_class_r ADD CONSTRAINT test_class_r_b_key UNIQUE (b); ALTER TABLE test_class_r ADD CONSTRAINT test_class_r_pkey PRIMARY KEY (a); ALTER TABLE test_class_r ADD CONSTRAINT test_class_r_c_check CHECK (c > 'Mon Jan 01 00:00:00 2001'::timestamp without time zone); CREATE UNIQUE INDEX idx1 ON public.test_class_r USING btree (lower(b)) WHERE (b IS NOT NULL); CREATE INDEX idx2 ON public.test_class_r USING gin (v); CREATE INDEX idx3 ON public.test_class_r USING btree (g) WITH (fillfactor='50'); CLUSTER test_class_r USING test_class_r_pkey; CREATE TRIGGER aaaa BEFORE UPDATE ON test_class_r FOR EACH ROW WHEN (old.* IS DISTINCT FROM new.*) EXECUTE PROCEDURE trig('AAAA'); ALTER TABLE test_class_r DISABLE TRIGGER aaaa; GRANT INSERT ON test_class_r TO PUBLIC; GRANT SELECT ON test_class_r TO PUBLIC; GRANT UPDATE ON test_class_r TO PUBLIC; GRANT DELETE ON test_class_r TO PUBLIC; GRANT TRUNCATE ON test_class_r TO PUBLIC; GRANT REFERENCES ON test_class_r TO PUBLIC; GRANT TRIGGER ON test_class_r TO PUBLIC; END; (1 row) SELECT ddlx_script('idx1'::regclass); ddlx_script BEGIN; /* DROP INDEX idx1; */ -- Type: INDEX ; Name: idx1; Owner: postgres CREATE UNIQUE INDEX idx1 ON public.test_class_r USING btree (lower(b)) WHERE (b IS NOT NULL); COMMENT ON INDEX idx1 IS NULL; END; (1 row) SELECT ddlx_script('idx2'::regclass); ddlx_script BEGIN; /* DROP INDEX idx2; */ -- Type: INDEX ; Name: idx2; Owner: postgres CREATE INDEX idx2 ON public.test_class_r USING gin (v); COMMENT ON INDEX idx2 IS NULL; END; (1 row) CREATE UNLOGGED TABLE test_class_r2 ( i serial, a int, cc char(20), vv varchar(20), n numeric(10,2), constraint "blah" foreign key (a) references test_class_r(a) ); -- alter table test_class_r2 set with oids; alter table test_class_r2 add constraint "blah2" foreign key (a) references test_class_r(a) deferrable initially deferred not valid; SELECT ddlx_script('test_class_r2'::regclass); ddlx_script BEGIN; /* ALTER TABLE test_class_r2 ALTER i DROP DEFAULT; DROP TABLE test_class_r2; */ -- Type: TABLE ; Name: test_class_r2; Owner: postgres CREATE UNLOGGED TABLE test_class_r2 ( i integer NOT NULL, a integer, cc character(20), vv character varying(20), n numeric(10,2) ); COMMENT ON TABLE test_class_r2 IS NULL; ALTER TABLE test_class_r2 OWNER TO postgres; ALTER SEQUENCE test_class_r2_i_seq OWNED BY test_class_r2.i; ALTER TABLE test_class_r2 ADD CONSTRAINT blah FOREIGN KEY (a) REFERENCES test_class_r(a); ALTER TABLE test_class_r2 ADD CONSTRAINT blah2 FOREIGN KEY (a) REFERENCES test_class_r(a) DEFERRABLE INITIALLY DEFERRED NOT VALID; -- DEPENDANTS ALTER TABLE test_class_r2 ALTER i SET DEFAULT nextval('test_class_r2_i_seq'::regclass); END; (1 row) CREATE VIEW test_class_v AS SELECT * FROM test_class_r; grant select on test_class_v to public; SELECT ddlx_script('test_class_v'::regclass); ddlx_script BEGIN; /* DROP VIEW test_class_v; */ -- Type: VIEW ; Name: test_class_v; Owner: postgres CREATE OR REPLACE VIEW test_class_v AS SELECT test_class_r.a, test_class_r.b, test_class_r.c, test_class_r.d, test_class_r.e, test_class_r.f, test_class_r.g, test_class_r.h, test_class_r.v FROM test_class_r; COMMENT ON VIEW test_class_v IS NULL; ALTER VIEW test_class_v OWNER TO postgres; GRANT SELECT ON test_class_v TO PUBLIC; END; (1 row) SELECT ddlx_script('test_class_v'::regtype); ddlx_script BEGIN; /* DROP VIEW test_class_v; */ -- Type: VIEW ; Name: test_class_v; Owner: postgres CREATE OR REPLACE VIEW test_class_v AS SELECT test_class_r.a, test_class_r.b, test_class_r.c, test_class_r.d, test_class_r.e, test_class_r.f, test_class_r.g, test_class_r.h, test_class_r.v FROM test_class_r; COMMENT ON VIEW test_class_v IS NULL; ALTER VIEW test_class_v OWNER TO postgres; GRANT SELECT ON test_class_v TO PUBLIC; END; (1 row) CREATE VIEW test_class_v2 AS SELECT * FROM test_class_v; grant select (a,b,c) on test_class_v2 to public; SELECT ddlx_script('test_class_v'::regclass); ddlx_script BEGIN; /* DROP VIEW test_class_v2; DROP VIEW test_class_v; */ -- Type: VIEW ; Name: test_class_v; Owner: postgres CREATE OR REPLACE VIEW test_class_v AS SELECT test_class_r.a, test_class_r.b, test_class_r.c, test_class_r.d, test_class_r.e, test_class_r.f, test_class_r.g, test_class_r.h, test_class_r.v FROM test_class_r; COMMENT ON VIEW test_class_v IS NULL; ALTER VIEW test_class_v OWNER TO postgres; GRANT SELECT ON test_class_v TO PUBLIC; -- DEPENDANTS -- Type: VIEW ; Name: test_class_v2; Owner: postgres CREATE OR REPLACE VIEW test_class_v2 AS SELECT test_class_v.a, test_class_v.b, test_class_v.c, test_class_v.d, test_class_v.e, test_class_v.f, test_class_v.g, test_class_v.h, test_class_v.v FROM test_class_v; COMMENT ON VIEW test_class_v2 IS NULL; ALTER VIEW test_class_v2 OWNER TO postgres; GRANT SELECT (a) ON test_class_v2 TO PUBLIC; GRANT SELECT (b) ON test_class_v2 TO PUBLIC; GRANT SELECT (c) ON test_class_v2 TO PUBLIC; END; (1 row) CREATE MATERIALIZED VIEW test_class_m AS SELECT * FROM test_class_r; create unique index test_class_mi ON test_class_m (a); SELECT ddlx_script('test_class_m'::regclass); ddlx_script BEGIN; /* DROP MATERIALIZED VIEW test_class_m; */ -- Type: MATERIALIZED VIEW ; Name: test_class_m; Owner: postgres CREATE MATERIALIZED VIEW test_class_m AS SELECT test_class_r.a, test_class_r.b, test_class_r.c, test_class_r.d, test_class_r.e, test_class_r.f, test_class_r.g, test_class_r.h, test_class_r.v FROM test_class_r; COMMENT ON MATERIALIZED VIEW test_class_m IS NULL; CREATE UNIQUE INDEX test_class_mi ON public.test_class_m USING btree (a); ALTER MATERIALIZED VIEW test_class_m OWNER TO postgres; END; (1 row) select sql_kind, sql_identifier from ddlx_identify('ddlx_identify(oid)'::regprocedure); sql_kind|sql_identifier FUNCTION|ddlx_identify(oid) (1 row) create function funfun(a int, b text default null, out c numeric, out d text) returns setof record as $$ select 3.14, 'now'::text $$ language sql cost 123 rows 19 set xmloption = content ; comment on function funfun(int,text) is 'Use more comments!'; select * from funfun(1); c|d 3.14|now (1 row) SELECT ddlx_script('funfun'::regproc); ddlx_script BEGIN; /* DROP FUNCTION funfun(integer,text); */ -- Type: FUNCTION ; Name: funfun(integer,text); Owner: postgres CREATE OR REPLACE FUNCTION public.funfun(a integer, b text DEFAULT NULL::text, OUT c numeric, OUT d text) RETURNS SETOF record LANGUAGE sql COST 123 ROWS 19 SET xmloption TO 'content' AS $function$ select 3.14, 'now'::text $function$; COMMENT ON FUNCTION funfun(integer,text) IS 'Use more comments!'; ALTER FUNCTION funfun(integer,text) OWNER TO postgres; REVOKE ALL ON FUNCTION funfun(integer,text) FROM PUBLIC; GRANT EXECUTE ON FUNCTION funfun(integer,text) TO PUBLIC; GRANT EXECUTE ON FUNCTION funfun(integer,text) TO postgres WITH GRANT OPTION; END; (1 row) SELECT ddlx_script('funfun(int,text)'::regprocedure); ddlx_script BEGIN; /* DROP FUNCTION funfun(integer,text); */ -- Type: FUNCTION ; Name: funfun(integer,text); Owner: postgres CREATE OR REPLACE FUNCTION public.funfun(a integer, b text DEFAULT NULL::text, OUT c numeric, OUT d text) RETURNS SETOF record LANGUAGE sql COST 123 ROWS 19 SET xmloption TO 'content' AS $function$ select 3.14, 'now'::text $function$; COMMENT ON FUNCTION funfun(integer,text) IS 'Use more comments!'; ALTER FUNCTION funfun(integer,text) OWNER TO postgres; REVOKE ALL ON FUNCTION funfun(integer,text) FROM PUBLIC; GRANT EXECUTE ON FUNCTION funfun(integer,text) TO PUBLIC; GRANT EXECUTE ON FUNCTION funfun(integer,text) TO postgres WITH GRANT OPTION; END; (1 row) create sequence test_type_S increment 4 start 2; comment on sequence test_type_S is 'interleave'; select ddlx_script('test_type_S'::regclass); ddlx_script BEGIN; /* DROP SEQUENCE IF EXISTS test_type_s; */ -- Type: SEQUENCE ; Name: test_type_s; Owner: postgres CREATE SEQUENCE test_type_s; ALTER SEQUENCE test_type_s INCREMENT BY 4 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 2 NO CYCLE; COMMENT ON SEQUENCE test_type_s IS 'interleave'; ALTER SEQUENCE test_type_s OWNER TO postgres; END; (1 row) create table test_collation ( id serial, c text collate "C" not null, t text ); select ddlx_script('test_collation'::regclass); ddlx_script BEGIN; /* ALTER TABLE test_collation ALTER id DROP DEFAULT; DROP TABLE test_collation; */ -- Type: TABLE ; Name: test_collation; Owner: postgres CREATE TABLE test_collation ( id integer NOT NULL, c text COLLATE "C" NOT NULL, t text ); COMMENT ON TABLE test_collation IS NULL; ALTER TABLE test_collation OWNER TO postgres; ALTER SEQUENCE test_collation_id_seq OWNED BY test_collation.id; -- DEPENDANTS ALTER TABLE test_collation ALTER id SET DEFAULT nextval('test_collation_id_seq'::regclass); END; (1 row) create view test_class_v_opt2 as select * from test_class_v order by 1; alter view test_class_v_opt2 set (security_barrier='true'); select ddlx_script('test_class_v_opt2'::regclass); ddlx_script BEGIN; /* DROP VIEW test_class_v_opt2; */ -- Type: VIEW ; Name: test_class_v_opt2; Owner: postgres CREATE OR REPLACE VIEW test_class_v_opt2 AS SELECT test_class_v.a, test_class_v.b, test_class_v.c, test_class_v.d, test_class_v.e, test_class_v.f, test_class_v.g, test_class_v.h, test_class_v.v FROM test_class_v ORDER BY test_class_v.a; COMMENT ON VIEW test_class_v_opt2 IS NULL; ALTER VIEW test_class_v_opt2 SET (security_barrier='true'); ALTER VIEW test_class_v_opt2 OWNER TO postgres; END; (1 row) select ddlx_script('test_class_v_opt2'::regclass::oid); ddlx_script BEGIN; /* DROP VIEW test_class_v_opt2; */ -- Type: VIEW ; Name: test_class_v_opt2; Owner: postgres CREATE OR REPLACE VIEW test_class_v_opt2 AS SELECT test_class_v.a, test_class_v.b, test_class_v.c, test_class_v.d, test_class_v.e, test_class_v.f, test_class_v.g, test_class_v.h, test_class_v.v FROM test_class_v ORDER BY test_class_v.a; COMMENT ON VIEW test_class_v_opt2 IS NULL; ALTER VIEW test_class_v_opt2 SET (security_barrier='true'); ALTER VIEW test_class_v_opt2 OWNER TO postgres; END; (1 row) select ddlx_script('test_class_v_opt2'); ddlx_script BEGIN; /* DROP VIEW test_class_v_opt2; */ -- Type: VIEW ; Name: test_class_v_opt2; Owner: postgres CREATE OR REPLACE VIEW test_class_v_opt2 AS SELECT test_class_v.a, test_class_v.b, test_class_v.c, test_class_v.d, test_class_v.e, test_class_v.f, test_class_v.g, test_class_v.h, test_class_v.v FROM test_class_v ORDER BY test_class_v.a; COMMENT ON VIEW test_class_v_opt2 IS NULL; ALTER VIEW test_class_v_opt2 SET (security_barrier='true'); ALTER VIEW test_class_v_opt2 OWNER TO postgres; END; (1 row) create or replace function test_proc_1() returns text as $$ select 'Hello, world!'::text $$ language sql; create or replace function test_proc_2(integer) returns text strict as $$ select b from test_class_r where a = $1 $$ language sql; select ddlx_script('test_proc_1'::regproc); ddlx_script BEGIN; /* DROP FUNCTION test_proc_1(); */ -- Type: FUNCTION ; Name: test_proc_1(); Owner: postgres CREATE OR REPLACE FUNCTION public.test_proc_1() RETURNS text LANGUAGE sql AS $function$ select 'Hello, world!'::text $function$; COMMENT ON FUNCTION test_proc_1() IS NULL; ALTER FUNCTION test_proc_1() OWNER TO postgres; REVOKE ALL ON FUNCTION test_proc_1() FROM PUBLIC; GRANT EXECUTE ON FUNCTION test_proc_1() TO PUBLIC; GRANT EXECUTE ON FUNCTION test_proc_1() TO postgres WITH GRANT OPTION; END; (1 row) select ddlx_script('test_proc_1'::regproc::oid); ddlx_script BEGIN; /* DROP FUNCTION test_proc_1(); */ -- Type: FUNCTION ; Name: test_proc_1(); Owner: postgres CREATE OR REPLACE FUNCTION public.test_proc_1() RETURNS text LANGUAGE sql AS $function$ select 'Hello, world!'::text $function$; COMMENT ON FUNCTION test_proc_1() IS NULL; ALTER FUNCTION test_proc_1() OWNER TO postgres; REVOKE ALL ON FUNCTION test_proc_1() FROM PUBLIC; GRANT EXECUTE ON FUNCTION test_proc_1() TO PUBLIC; GRANT EXECUTE ON FUNCTION test_proc_1() TO postgres WITH GRANT OPTION; END; (1 row) select ddlx_script('test_proc_1()'); ddlx_script BEGIN; /* DROP FUNCTION test_proc_1(); */ -- Type: FUNCTION ; Name: test_proc_1(); Owner: postgres CREATE OR REPLACE FUNCTION public.test_proc_1() RETURNS text LANGUAGE sql AS $function$ select 'Hello, world!'::text $function$; COMMENT ON FUNCTION test_proc_1() IS NULL; ALTER FUNCTION test_proc_1() OWNER TO postgres; REVOKE ALL ON FUNCTION test_proc_1() FROM PUBLIC; GRANT EXECUTE ON FUNCTION test_proc_1() TO PUBLIC; GRANT EXECUTE ON FUNCTION test_proc_1() TO postgres WITH GRANT OPTION; END; (1 row) CREATE AGGREGATE test_proc_agg_1(text) ( SFUNC = textcat, STYPE = text ); select ddlx_script('test_proc_agg_1'::regproc); ddlx_script BEGIN; /* DROP AGGREGATE test_proc_agg_1(text); */ -- Type: AGGREGATE ; Name: test_proc_agg_1(text); Owner: postgres CREATE AGGREGATE test_proc_agg_1(text) ( SFUNC = textcat, STYPE = text ); COMMENT ON AGGREGATE test_proc_agg_1(text) IS NULL; ALTER AGGREGATE test_proc_agg_1(text) OWNER TO postgres; REVOKE ALL ON FUNCTION test_proc_agg_1(text) FROM PUBLIC; GRANT EXECUTE ON FUNCTION test_proc_agg_1(text) TO PUBLIC; GRANT EXECUTE ON FUNCTION test_proc_agg_1(text) TO postgres WITH GRANT OPTION; END; (1 row) CREATE AGGREGATE test_proc_agg_2(anyelement) ( SFUNC = array_append, STYPE = anyarray, INITCOND = '{}' ); select ddlx_script('test_proc_agg_2'::regproc); ddlx_script BEGIN; /* DROP AGGREGATE test_proc_agg_2(anyelement); */ -- Type: AGGREGATE ; Name: test_proc_agg_2(anyelement); Owner: postgres CREATE AGGREGATE test_proc_agg_2(anyelement) ( SFUNC = array_append, STYPE = anyarray, INITCOND = '{}' ); COMMENT ON AGGREGATE test_proc_agg_2(anyelement) IS NULL; ALTER AGGREGATE test_proc_agg_2(anyelement) OWNER TO postgres; REVOKE ALL ON FUNCTION test_proc_agg_2(anyelement) FROM PUBLIC; GRANT EXECUTE ON FUNCTION test_proc_agg_2(anyelement) TO PUBLIC; GRANT EXECUTE ON FUNCTION test_proc_agg_2(anyelement) TO postgres WITH GRANT OPTION; END; (1 row) ----- create table test_parent ( i serial ); create table test_child () inherits (test_parent); select ddlx_create('test_parent'::regclass); ddlx_create -- Type: TABLE ; Name: test_parent; Owner: postgres CREATE TABLE test_parent ( i integer NOT NULL ); COMMENT ON TABLE test_parent IS NULL; ALTER TABLE test_parent OWNER TO postgres; ALTER SEQUENCE test_parent_i_seq OWNED BY test_parent.i; (1 row) select ddlx_create('test_child'::regclass); ddlx_create -- Type: TABLE ; Name: test_child; Owner: postgres CREATE TABLE test_child () INHERITS(test_parent); COMMENT ON TABLE test_child IS NULL; ALTER TABLE test_child OWNER TO postgres; ALTER TABLE test_child ALTER i SET DEFAULT nextval('test_parent_i_seq'::regclass); (1 row)