Re: indexing

From: "Tim White" <twhite26(at)kc(dot)rr(dot)com>
To: <s(at)remail(dot)net>
Cc: <pgsql-admin(at)postgresql(dot)org>
Subject: Re: indexing
Date: 2001-02-26 17:18:59
Message-ID: 008701c0a018$3559f100$5b02010a@dashrendar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Use an sequence. Add the ID column to your create table statement and set
the default to use the next value from the sequence. This will give each
entry a unique id number. The syntax would be as follows.

create sequence customer_id start 1 increment 1 maxvalue 2147483647 minvalue
1 cache 1;

create table customer(
cust_id int unique not null default nextval('customer_id'),
last_name varchar(....
)

This will create a database sequence, and then each time you insert a
customer, if you don't specify a cust_id, it will default to the next value
in the sequence.

Tim White

----- Original Message -----
From: "si" <s(at)remail(dot)net>
To: <pgsql-admin(at)postgresql(dot)org>
Sent: Monday, February 26, 2001 9:04 AM
Subject: [ADMIN] indexing

> Hi,
>
> I am new to postgresql, Please can you guide me:
>
> I have created a table and I would like all the entries to be indexed with
a number when the data is entered into the database, hence giving it a new
id, every time some data is entered.
>
> e.g.
>
> I.D. | Name
> 1 | Jack
> 2 | Jill
>
>
> Does pgsql do this automatically? or do I have to create a seprate ID
field like above, and check the database each time the data is entered and
find out the highest number then increment it by 1 and then enter the data
with the incremented number.
>
> If it automatically indexes the names when they are entered in to the
database, Please can you show me how to find this index.
>
> Thanks,
> Si
>
> _____________________________________________________________
> Pick up your email anywhere in the world ---> http://www.remail.net

In response to

  • indexing at 2001-02-26 15:04:50 from si

Browse pgsql-admin by date

  From Date Subject
Next Message lbottorff 2001-02-26 17:41:33 Default not triggering
Previous Message Stephan Szabo 2001-02-26 16:58:47 Re: not use pg_dump & pg_dumpall