passing column name to a PL/pgsql function for ALTER TABLE ADD

From: Alexander Kotelnikov <sacha(at)myxomop(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: passing column name to a PL/pgsql function for ALTER TABLE ADD
Date: 2005-08-11 10:50:11
Message-ID: 87vf2c928s.fsf@myxomop.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Alexander Kotelnikov 2005-08-11 12:03:45 Re: Transaction blocks
Previous Message Vanessa Conchodon 2005-08-11 10:09:56 connection trouble