Re: Generating unique values for TEXT columns

From: "Joost Kraaijeveld" <J(dot)Kraaijeveld(at)Askesis(dot)nl>
To: "Frank D(dot) Engel, Jr(dot)" <fde101(at)fjrhome(dot)net>
Cc: "Pgsql-General (E-mail)" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Generating unique values for TEXT columns
Date: 2005-01-03 17:03:43
Message-ID: A3D1526C98B7C1409A687E0943EAC41048A072@obelix.askesis.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Frank

I use the following constructs to generate an objectid's in my database:

CREATE SEQUENCE public.tsfraction MAXVALUE 999999;

CREATE FUNCTION getobjectid() RETURNS text
AS '
select((select(to_char(current_timestamp, \'yyyy-mm-dd-hh-mm-ss\'))) || (select(to_char((nextval(\'tsfraction\')),\'-FM000000MI\')))) as return;
'
LANGUAGE 'sql';

CREATE TABLE public.object
(
objectid text NOT NULL DEFAULT getobjectid(),
-- other columns omited
CONSTRAINT pk_object PRIMARY KEY (objectid)
) WITH OIDS;

Groeten,

Joost Kraaijeveld
Askesis B.V.
Molukkenstraat 14
6524NB Nijmegen
tel: 024-3888063 / 06-51855277
fax: 024-3608416
e-mail: J(dot)Kraaijeveld(at)Askesis(dot)nl
web: www.askesis.nl

Browse pgsql-general by date

  From Date Subject
Next Message Josué Maldonado 2005-01-03 17:07:42 Re: Generating unique values for TEXT columns
Previous Message Frank D. Engel, Jr. 2005-01-03 16:53:44 Generating unique values for TEXT columns