Thread: [URGENT] How to generata a unique string id

[URGENT] How to generata a unique string id

From
Manuel Durán Aguete
Date:
    Hi,

    I need to generate a unique four letters string (p.e
AAAA,AAAB) for any tuple I insert into a table, any idea ? How can I do
this ?

                        Thanks.

--
Manuel Durán Aguete
ALSERNET 2000 S.L
http://www.alsernet.es
Tlf: 902 187 187
Fax: 981 179 121




Re: [URGENT] How to generata a unique string id

From
"Richard Huxton"
Date:
From: "Manuel Durán Aguete" <mdaguete@alsernet.es>

> I need to generate a unique four letters string (p.e
> AAAA,AAAB) for any tuple I insert into a table, any idea ? How can I do
> this ?

Create a sequence foo_seq and then set your field

create table example (
  id default myfunc(nextval(foo_seq)),
  a text,
  b int4
);

Define myfunc to convert the integer into a character string (take the value
mod 26, append to string, divide value by 26, repeat)

- Richard Huxton