From: | Jake Stride <jake(at)stride(dot)me(dot)uk> |
---|---|
To: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Function Question |
Date: | 2011-12-08 23:22:33 |
Message-ID: | CABO-GFSNxsK0T756EPdXVa3cH8W_tx_j0b8CSfZONt=h+=gHhw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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).
I have tried putting the key into a variable and using no quotes but
it either errors or gives me "NEW.key" rather than "whatever-uuid-was
inserted".
Please can anybody give me some pointers?
Thanks
Jake
CREATE OR REPLACE FUNCTION public.setup_sequence()
RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
sequence_name UUID;
BEGIN
IF (
TG_OP = 'INSERT' AND
NEW.type = 'auto_increment'
) THEN
SELECT NEW.key INTO STRICT sequence_name;
-- Set up the sequence
CREATE SEQUENCE \"NEW.key\";
-- Set the start value
--SELECT SETVAL(sequence_name, NEW.auto_increment_default);
END IF;
RETURN NEW;
END;
From | Date | Subject | |
---|---|---|---|
Next Message | Rodger Donaldson | 2011-12-09 00:09:34 | Re: Hope for a new PostgreSQL era? |
Previous Message | Raymond O'Donnell | 2011-12-08 23:20:47 | Re: |