Re: newid() in postgres

From: "Postgres User" <postgres(dot)developer(at)gmail(dot)com>
To: "Peter Eisentraut" <peter_e(at)gmx(dot)net>
Cc: pgsql-general(at)postgresql(dot)org, marcel(dot)beutner <m(dot)beutner(at)googlemail(dot)com>
Subject: Re: newid() in postgres
Date: 2007-04-05 03:24:29
Message-ID: b88c3460704042024n497f18edxca83d11b8558f6e2@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Marcel,

A sequence represents a unique identifier. You can call the function
'nextval' to get the next unique value in the sequence. See related
functions here:

http://www.postgresql.org/docs/8.2/interactive/functions-sequence.html

In this code, I get the next sequence, insert it into a table, and
then return the value to the calling function:

DECLARE
nextseq integer;

BEGIN
nextseq := nextval('entry_id_seq');

INSERT INTO my_table (
entry_id,
entry_text,
) VALUES (
nextseq,
p_entry_text, -- input param
);

On 4/4/07, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> marcel.beutner wrote:
> > I've searched in the groups already, but couldn't find any helpful
> > information - only to use a sequence, which returns just a number and
> > not a unique identifier.
>
> Which properties do your unique identifiers posses that are not
> satisfied by a number returned by a sequence?
>
> --
> Peter Eisentraut
> http://developer.postgresql.org/~petere/
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Postgres User 2007-04-05 03:33:44 Re: Need your help on using "partion"
Previous Message Nikolay Moskvichev 2007-04-05 02:25:32 Re: Storing blobs in PG DB