Re: Generating unique session ids

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Antimon" <antimon(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Generating unique session ids
Date: 2006-07-26 22:08:23
Message-ID: 18819.1153951703@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Antimon" <antimon(at)gmail(dot)com> writes:
> As the id field is primary key, it should generate a unique violation
> if duplicate ids created, might be seen rarely but wanted to solve it
> anyway.

Why don't you just use a serial generator?

So i decided to check it by changing "sid := md5(random());" to
> "sid := extract(minute from now());" When i run it, returns the minute
> as session key and inserts an entryy for it, but if i call it again in
> the same minute, it never ends execution. I expected it to return the
> minute when system clock minute changes but it runs forever.

Yup, see
http://www.postgresql.org/docs/8.1/static/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Shoaib Mir 2006-07-26 22:15:45 Re: Table Inheritence...Just Columns?
Previous Message Antimon 2006-07-26 21:54:47 Generating unique session ids