Skip site navigation (1) Skip section navigation (2)

Re: Need help with currval and nextvall...

From: Philip Hallstrom <philip(at)adhesivemedia(dot)com>
To: Dan Jewett <danjewett(at)mac(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Need help with currval and nextvall...
Date: 2002-11-22 19:05:08
Message-ID: 20021122110431.M94740-100000@cypress.adhesivemedia.com (view raw or flat)
Thread:
Lists: pgsql-novice
You need to quote (single quotes) the name of the sequence... and you need
to use nextval('album_album_id_seq') before calling currval().

At least I think so.

On Fri, 22 Nov 2002, Dan Jewett wrote:

> 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
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
>


In response to

Responses

pgsql-novice by date

Next:From: Dan JewettDate: 2002-11-22 19:27:42
Subject: Re: Need help with currval and nextvall...
Previous:From: Dan JewettDate: 2002-11-22 18:49:22
Subject: Need help with currval and nextvall...

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group