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).