Project

General

Profile

« Previous | Next » 

Revision 8153

schemas/functions.sql: Added set_col_names()

View differences:

schemas/functions.sql
765 765

  
766 766

  
767 767
--
768
-- Name: set_col_names(regclass, regclass); Type: FUNCTION; Schema: functions; Owner: -
769
--
770

  
771
CREATE FUNCTION set_col_names(table_ regclass, names regclass) RETURNS void
772
    LANGUAGE plpgsql STRICT
773
    AS $_$
774
DECLARE
775
    old text[] = ARRAY(SELECT functions.col_names(table_));
776
    new text[] = ARRAY(SELECT functions.map_values(names));
777
BEGIN
778
    old = old[1:array_length(new, 1)]; -- truncate to same length
779
    PERFORM functions.rename_if_exists($$ALTER TABLE $$||$1||$$ RENAME $$
780
        ||quote_ident(key)||$$ TO $$||quote_ident(value))
781
    FROM each(hstore(old, new));
782
END;
783
$_$;
784

  
785

  
786
--
787
-- Name: FUNCTION set_col_names(table_ regclass, names regclass); Type: COMMENT; Schema: functions; Owner: -
788
--
789

  
790
COMMENT ON FUNCTION set_col_names(table_ regclass, names regclass) IS 'idempotent';
791

  
792

  
793
--
768 794
-- Name: set_col_types(regclass, col_cast[]); Type: FUNCTION; Schema: functions; Owner: -
769 795
--
770 796

  

Also available in: Unified diff