Re: Function Question

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jake Stride <jake(at)stride(dot)me(dot)uk>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Function Question
Date: 2011-12-09 03:16:23
Message-ID: 14383.1323400583@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jake Stride <jake(at)stride(dot)me(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Clay 2011-12-09 03:54:31 Character encoding problems
Previous Message Craig Ringer 2011-12-09 03:13:42 Re: Hope for a new PostgreSQL era?