![]() Vidx = vidx || E'\nCREATE INDEX ' || cidx || ' ON ' || ptable || ' (' WHERE c.relname = ptable AND i.indisunique != 't' AND i.indisprimary != 't' LEFT JOIN pg_stat_user_indexes s USING (indexrelid) ![]() LEFT JOIN pg_attribute a ON a.attrelid = c.oid AND a.attnum = ANY(i.indkey) Vsql = substr(vsql,1,length(vsql)-1) || ') WITHOUT OIDS' įOR ridx IN SELECT s.indexrelname as nome, a.attname as colįROM pg_index i LEFT JOIN pg_class c ON c.oid = i.indrelid Vkey = E'\nCONSTRAINT ' || rkey.name || ' PRIMARY KEY (' Vsql = vsql || ' DEFAULT ' || ldef įOR rkey IN SELECT constraint_name as name, column_name as col Numeric_precision as num_prec, numeric_scale as num_scale Is_nullable as is_null, character_maximum_length as len, Source code: CREATE OR REPLACE FUNCTION xaddcolumn(ptable text, pcol text, pafter text) RETURNS void AS $BODY$ĮXECUTE 'CREATE TABLE zzz_' || ptable || ' AS SELECT * FROM ' || ptable įOR rcol IN SELECT column_name as col, udt_name as coltype, column_default as coldef, Missing Views and Foreign Key and other features are missing.Įxample: SELECT xaddcolumn('table', 'col3 int NOT NULL DEFAULT 0', 'col2') It works with indexes, primary key, and triggers. The column order is relevant to me, so I created this function.
0 Comments
Leave a Reply. |