| From: | Dan Jewett <danjewett(at)mac(dot)com> |
|---|---|
| To: | pgsql-novice(at)postgresql(dot)org |
| Subject: | |
| Date: | 2002-11-22 18:33:37 |
| Message-ID: | p05200f09ba0423d35c2e@[162.84.132.56] |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-novice |
Considering the function below, is it possible to get the value of
the album_id from the first INSERT statement and use it in the 2nd
INSERT statement as I have tried to do here? Or do has the sequence
not update until the end of the LOOP?
I have tried this and get: ERROR: Attribute 'album_album_id_seq' not found
How would I accomplish this?
CREATE FUNCTION catalog_batch() RETURNS text AS '
DECLARE
myrec RECORD;
BEGIN
FOR myrec IN SELECT * FROM catalog LOOP
INSERT INTO album (columns,....) VALUES ('matching values',....);
INSERT INTO track (columns,....) VALUES (
currval(album_album_id_seq), 'other matching values',.... );
<rest of code>
END LOOP;
RETURN 'Batch Complete';
END;
' LANGUAGE 'plpgsql';
Thanks,
Dan Jewett
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Dan Jewett | 2002-11-22 18:49:22 | Need help with currval and nextvall... |
| Previous Message | Dan Jewett | 2002-11-22 18:05:11 | Re: function does not exist error... |