passing column name to a PL/pgsql function for ALTER TABLE ADD - Mailing list pgsql-novice

From Alexander Kotelnikov
Subject passing column name to a PL/pgsql function for ALTER TABLE ADD
Date
Msg-id 87vf2c928s.fsf@myxomop.com
Whole thread Raw
Responses Re: passing column name to a PL/pgsql function for ALTER TABLE ADD
List pgsql-novice
Hello.

Is it possible? I would like to do something like
CREATE OR REPLACE FUNCTION add_column(name, anyelement) RETURNS integer AS '
  DECLARE
    col_name ALIAS FOR $1;
    def_val  ALIAS FOR $2;
  BEGIN
    ALTER TABLE my_table ADD col_name def_val%TYPE;
    RETURN 0;
  END;
' LANGUAGE plpgsql;
SELECT add_column('a', 1);

Thanks,
--
Alexander Kotelnikov
Saint-Petersburg, Russia

pgsql-novice by date:

Previous
From: Vanessa Conchodon
Date:
Subject: connection trouble
Next
From: Alexander Kotelnikov
Date:
Subject: Re: Transaction blocks