From: | Graf László <graf(dot)laszlo(at)axis(dot)hu> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Returning with the inserted id |
Date: | 2005-09-02 09:09:37 |
Message-ID: | 431816D1.4060905@axis.hu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hi all
A table was created with:
CREATE TABLE test (
id integer,
nev varchar(25),
datum timestamp
);
A sequence to hold the id was defined with:
CREATE SEQUENCE "public"."test_azon_seq"
INCREMENT 1 MINVALUE 101
MAXVALUE 9223372036854775807 START 101
CACHE 1;
The function wich allocates the id and defines the datum is:
CREATE FUNCTION test_verif() RETURNS trigger AS $test_verif$
BEGIN
select into NEW.id nextval('test_azon_seq');
NEW.datum := current_timestamp;
RETURN NEW;
END;
$test_verif$ LANGUAGE plpgsql;
and the before insert trigger is:
CREATE TRIGGER test_verif
BEFORE INSERT ON test
FOR EACH ROW
EXECUTE PROCEDURE test_verif();
When I issue an insert (see below) how can I retrieve the
inserted value of id? I need something like Oracle's returns
for insert.
insert into "public"."test" (nev) values ('text');
--
László Graf
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2005-09-02 09:33:36 | Re: Returning with the inserted id |
Previous Message | Graf László | 2005-09-02 07:26:04 | ERROR: syntax error at or near "select" at character 9 |