RE: [SQL] Autogenerated Unique Index

From: Andrzej Mazurkiewicz <andrzej(dot)mazurkiewicz(at)polkomtel(dot)com(dot)pl>
To: "'Antonio W(dot) Lagnada'" <alagnada(at)lsil(dot)com>
Cc: Pgsql-sql <pgsql-sql(at)postgreSQL(dot)org>
Subject: RE: [SQL] Autogenerated Unique Index
Date: 2000-03-07 15:37:30
Message-ID: 13288F4408ADD11186FF0060B06A431303648CA6@MSGWAW1
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> -----Original Message-----
> From: Antonio W. Lagnada [SMTP:alagnada(at)lsil(dot)com]
> Sent: 7 marca 2000 16:29
> To: Andrzej Mazurkiewicz
> Cc: Pgsql-sql
> Subject: Re: [SQL] Autogenerated Unique Index
>
> Hi Andrzej,
>
> From reading the Users Guide, I came up with this example
[Andrzej Mazurkiewicz]
[Andrzej Mazurkiewicz] CREATE SEQUENCE id START 1;

[Andrzej Mazurkiewicz]
> # To create the table with the auto-incrementing index
> CREATE TABLE customer ( id [Andrzej Mazurkiewicz] int , firstname
> VARCHAR(30), lastname VARCHAR(30)
> );
>
> # To insert
> INSERT INTO customer VALUES ( NEXTVAL('id'),'John','Doe');
> INSERT INTO customer VALUES ( NEXTVAL('id'),'Jane','Doe');
[Andrzej Mazurkiewicz] please remember that the above id refers to
SERIAL name not to column name !

> # This should create a record:
>
> id firstname lastname
> -- --------- --------
> 1 John Doe
> 2 Jane Doe
>
> Am I correcto to assume all this?
>
> -- Antonio
>
> Andrzej Mazurkiewicz wrote:
>
> > Sorry I have misunderstood your question. I automatically creates
> primary
> > (it is more than unique) INDEX.
> > I include an example from Postgres Users Manual - CREATE SERIAL section:
> >
> > CREATE SEQUENCE serial START 101;
> >
> >
> > Select the next number from this sequence
> >
> > SELECT NEXTVAL ('serial');
> >
> > nextval
> > -------
> > 114
> >
> >
> > Use this sequence in an INSERT:
> >
> > INSERT INTO distributors VALUES (NEXTVAL('serial'),'nothing');
> >
> >
> > Set the sequence value after a COPY FROM:
> >
> > CREATE FUNCTION distributors_id_max() RETURNS INT4
> > AS 'SELECT max(id) FROM distributors'
> > LANGUAGE 'sql';
> > BEGIN;
> > COPY distributors FROM 'input_file';
> > SELECT setval('serial', distributors_id_max());
> > END;
> >
> >
> > I hope it wiull help.
> > Regards,
> > Andrzej Mazurkiewicz
> >
> > andrzej(at)mazurkiewicz(dot)org
> >
> > www.mazurkiewicz.org
> >
> > > -----Original Message-----
> > > From: Antonio W. Lagnada [SMTP:alagnada(at)lsil(dot)com]
> > > Sent: 7 marca 2000 16:05
> > > To: Andrzej Mazurkiewicz
> > > Cc: Pgsql-sql
> > > Subject: Re: [SQL] Autogenerated Unique Index
> > >
> > > Hi Andrzej,
> > >
> > > Does this mean that everytime I create a new record on the table, the
> > > field
> > > "B" will be automatically incremented?
> > >
> > > - Antonio
> > >
> > > Andrzej Mazurkiewicz wrote:
> > >
> > > > cfmg_adm=> CREATE TABLE A (
> > > > cfmg_adm(> B int NOT NULL,
> > > > cfmg_adm(> C char(5),
> > > > cfmg_adm(> PRIMARY KEY (B)
> > > > cfmg_adm(> );
> > > > NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index
> 'a_pkey'
> > > for
> > > > table
> > > > 'a'
> > > > CREATE
> > > > cfmg_adm=>
> > > > Regards,
> > > > Andrzej Mazurkiewicz
> > > >
> > > > > -----Original Message-----
> > > > > From: Antonio W. Lagnada [SMTP:alagnada(at)lsil(dot)com]
> > > > > Sent: 7 marca 2000 14:41
> > > > > To: Pgsql-sql
> > > > > Subject: [SQL] Autogenerated Unique Index
> > > > >
> > > > > Can someone give me a step-by-step instructions on how to generate
> a
> > > > > unique autogenerated index in PostgreSQL?
> > > > >
> > > > > --
> > > > > Antonio W. Lagnada
> > > > >
> > > > >
> > > > > 952.921.8533
> > > > > alagnada(at)lsil(dot)com_NOSPAM
> > > > > Remove the _NOSPAM for
> > > > > the actual email address
> > > > > << File: Card for Antonio W. Lagnada >>
> > >
> > > --
> > > Antonio W. Lagnada
> > >
> > > 952.921.8533
> > > alagnada(at)lsil(dot)com_NOSPAM
> > > Remove the _NOSPAM for
> > > the actual email address
> > > << File: Card for Antonio W. Lagnada >>
>
> --
> Antonio W. Lagnada
>
> 952.921.8533
> alagnada(at)lsil(dot)com_NOSPAM
> Remove the _NOSPAM for
> the actual email address
> << File: Card for Antonio W. Lagnada >>

Browse pgsql-sql by date

  From Date Subject
Next Message Trurl McByte 2000-03-07 15:37:53 Re: [SQL] Autogenerated Unique Index
Previous Message Ross J. Reedstrom 2000-03-07 15:32:45 Re: [SQL] Autogenerated Unique Index