passing column name to a plpgsql 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 plpgsql function for ALTER TABLE ADD
Date: 2005-08-09 11:49:48
Message-ID: 87k6iv9voj.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);
--
Alexander Kotelnikov
Saint-Petersburg, Russia

Browse pgsql-novice by date

  From Date Subject
Next Message Jim Jarrett 2005-08-09 13:14:50 Suspend Referential Integrity?
Previous Message Tom Lane 2005-08-09 01:19:05 Re: Date Arithmetic in PL/pgSql