Re: [SQL] Unique Number KEY - Mailing list pgsql-sql

From CIMPOESU Teodor
Subject Re: [SQL] Unique Number KEY
Date
Msg-id 36D6E70D.ACF4CB7D@digiro.net
Whole thread Raw
In response to Unique Number KEY  ("Patrice DUMAS" <pdumas@inforoutes-ardeche.fr>)
List pgsql-sql
Patrice DUMAS wrote:

> Hello,
>
> What is the best way, with PostGres, to create a Unique Number Key
> Generator?
>
> For example, I have a STUDENTS table:
> {
>     StudentNumber    integer;
>     StudentName      char[40];
> ...
> }

you have 2 ways to do it:
1. try something like
      CREATE TABLE  STUDENTS(
           studentID  int4 DEFAULT 'int(now())',
          studentName text );
then if you say:
 INSERT INTO STUDENTS (studentName) VALUES ('Patrice DUMAS jr.') ;
you will get an unique ID generated from a timestamp returned by now() .

2. by using a sequence.See \h create sequence and nextval() function.
      This is a better way to get an ordered ID ( with an increment specified
by you).




pgsql-sql by date:

Previous
From: "Patrice DUMAS"
Date:
Subject: Unique Number KEY
Next
From: "Jackson, DeJuan"
Date:
Subject: RE: [SQL] Unique Number KEY