Re: Foreign key error, please help. - Mailing list pgsql-novice

From
Subject Re: Foreign key error, please help.
Date
Msg-id 20050309180125.61161.qmail@web52402.mail.yahoo.com
Whole thread Raw
In response to Foreign key error, please help.  (Kumar S <ps_postgres@yahoo.com>)
List pgsql-novice
--- Kumar S <ps_postgres@yahoo.com> wrote:
> Hi Stephan,
> Thank you very much, it was my stupid mistake.
>
> One more question. aplogies if this is also not so
> worthy question.
> In a transaction does currval work only if a
> previous
> statement defines it.  In my case I wanted to get FK
> from existing currval in sample table (sample_id).
> when I execute my statements in a transasction, I
> get
> the following error. Do I have to just use a SELECT
> statement here, because currval is not working? Or
> did
> i made a mistake instead?
>
> Thank you.

curval reports the most recent value of nextval
(serial datatype).  nextval automatically occurs on an
insert.  therefore, when you do an insert, you don't
need to specifically call nextval, it has already been
done by postgres.

yes, you need to SELECT the fk from the row in
question if you have not done and insert or if nextval
was never called.






__________________________________
Celebrate Yahoo!'s 10th Birthday!
Yahoo! Netrospective: 100 Moments of the Web
http://birthday.yahoo.com/netrospective/

pgsql-novice by date:

Previous
From: Sean
Date:
Subject: Exporting Tables
Next
From: John DeSoi
Date:
Subject: Re: VERY basic psql and schema question