Revision 8212
Added by Aaron Marcuse-Kubitza over 11 years ago
util.sql | ||
---|---|---|
821 | 821 |
CREATE FUNCTION rename_cols(table_ regclass, renames anyelement) RETURNS void |
822 | 822 |
LANGUAGE sql STRICT |
823 | 823 |
AS $_$ |
824 |
SELECT util.rename_if_exists($$ALTER TABLE $$||$1||$$ RENAME $$
|
|
824 |
SELECT util.try_create($$ALTER TABLE $$||$1||$$ RENAME $$
|
|
825 | 825 |
||quote_ident(name)||$$ TO $$||quote_ident($2 -> name)) |
826 | 826 |
FROM util.col_names($1::text::regtype) f (name) |
827 | 827 |
$_$; |
... | ... | |
858 | 858 |
new text[] = ARRAY(SELECT util.map_values(names)); |
859 | 859 |
BEGIN |
860 | 860 |
old = old[1:array_length(new, 1)]; -- truncate to same length |
861 |
PERFORM util.rename_if_exists($$ALTER TABLE $$||$1||$$ RENAME $$
|
|
861 |
PERFORM util.try_create($$ALTER TABLE $$||$1||$$ RENAME $$
|
|
862 | 862 |
||quote_ident(key)||$$ TO $$||quote_ident(value)) |
863 | 863 |
FROM each(hstore(old, new)); |
864 | 864 |
END; |
Also available in: Unified diff
schemas/util.sql: Renamed rename_if_exists() to try_create() because it can be used to create a column in any way, not just by renaming another column