| From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
|---|---|
| To: | JORGE MALDONADO <jorgemal1960(at)gmail(dot)com> |
| Cc: | pgsql-novice <pgsql-novice(at)postgresql(dot)org> |
| Subject: | Re: Getting Sequence Value |
| Date: | 2019-01-23 00:58:07 |
| Message-ID: | CAKFQuwbv00CT2vSi19izdEWPSEgAt8hp7P+i46ov3Jxv0c7S-w@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-novice |
On Tuesday, January 22, 2019, JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>
wrote:
> I need to get the sequence value of a table before inserting a new
> record, so I am using *currval, *but I am getting an error stating that
> "currval is not defined for this session". I tried using *nextval*, but
> the sequence skips one value because *nextval* increments by one and also
> an additional increment is preformed by the *insert* operation.
>
> How can I get the next available value avoiding these issues?
>
>
Use nextval but don’t throw the value away but pass it into the INSERT
statement. Or rewrite so you perform the auto-increment and maybe use
“RETURNING” to obtain the ID after the fact.
Dave
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Michael Holzman | 2019-01-25 08:39:17 | pl/SQL debugging in PostgreSQL |
| Previous Message | JORGE MALDONADO | 2019-01-23 00:43:10 | Getting Sequence Value |