Re: Function Question - Mailing list pgsql-general

From Tom Lane
Subject Re: Function Question
Date
Msg-id 14383.1323400583@sss.pgh.pa.us
Whole thread Raw
In response to Function Question  (Jake Stride <jake@stride.me.uk>)
List pgsql-general
Jake Stride <jake@stride.me.uk> writes:
> I am trying to create a function that gets fired when a new row is
> inserted. I can get the following function built but my problem is
> that the sequence that is created is called "NEW.key" rather than the
> value that is being inserted (it should be a UUID).

Instead of this:

>             CREATE SEQUENCE \"NEW.key\";

you need to do something like this:

            EXECUTE 'CREATE SEQUENCE ' || quote_ident(NEW.key);

The reason is that utility statements don't accept parameters natively,
so you have to construct the command as a string and then EXECUTE it.

            regards, tom lane

pgsql-general by date:

Previous
From: Craig Ringer
Date:
Subject: Re: Hope for a new PostgreSQL era?
Next
From: Chris Travers
Date:
Subject: Re: Hope for a new PostgreSQL era?