dbTalk Databases Forums  

Primary Key

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Primary Key in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Eduardo V. Rodríguez
 
Posts: n/a

Default Primary Key - 06-14-2004 , 07:17 PM






Hi

I try to do the following in a table that has 4 columns,

id - month - day- time

The column id is the primary key, for example

id - month . day - time
1 Jan 22 16:15
2 Jan 22 16:16
3 Jan 22 16:17
4 Jan 22 16:18

But I pretend that automatically when I made an INSERT INTO table (month,
day, time) values (A,B,C) the primary key update his value increasing by one


I dont know how to do this, Iam using Postgres 7.4 with PgAdminIII

Thank you

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


Reply With Quote
  #2  
Old   
Mike G
 
Posts: n/a

Default Re: Primary Key - 06-14-2004 , 11:34 PM







If you want to use a primary key that increase in value by one each time consider using a sequence.

See http://www.postgresql.org/docs/7.4/s...esequence.html

On Mon, Jun 14, 2004 at 07:17:37PM -0500, Eduardo V. Rodríguez wrote:
Quote:
Hi

I try to do the following in a table that has 4 columns,

id - month - day- time

The column id is the primary key, for example

id - month . day - time
1 Jan 22 16:15
2 Jan 22 16:16
3 Jan 22 16:17
4 Jan 22 16:18

But I pretend that automatically when I made an INSERT INTO table (month,
day, time) values (A,B,C) the primary key update his value increasing by one


I dont know how to do this, Iam using Postgres 7.4 with PgAdminIII

Thank you

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org



Reply With Quote
  #3  
Old   
Nabil Sayegh
 
Posts: n/a

Default Re: Primary Key - 06-15-2004 , 04:55 AM



Eduardo V. Rodríguez wrote:

Quote:
id - month . day - time
1 Jan 22 16:15
2 Jan 22 16:16
3 Jan 22 16:17
4 Jan 22 16:18

But I pretend that automatically when I made an INSERT INTO table (month,
day, time) values (A,B,C) the primary key update his value increasing by one
CREATE TABLE foo (id_foo SERIAL PRIMARY KEY, month ...);

SERIAL is of type int creates automatically a sequence that increments each time you don't specify
the id in an INSERT.

HTH
--
e-Trolley Sayegh & John, Nabil Sayegh
Tel.: 0700 etrolley /// 0700 38765539
Fax.: +49 69 8299381-8
PGP : http://www.e-trolley.de

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings



Reply With Quote
  #4  
Old   
Eduardo V. Rodríguez
 
Posts: n/a

Default Re: Primary Key - 06-16-2004 , 02:12 PM



Ok thanks for all the ideas I got it

-----Original Message-----
From: Bruno Wolff III [mailto:bruno (AT) wolff (DOT) to]
Sent: Wednesday, June 16, 2004 1:13 PM
To: Eduardo V. Rodríguez
Cc: Postgres (E-mail)
Subject: Re: [NOVICE] Primary Key


On Mon, Jun 14, 2004 at 19:17:37 -0500,
"Eduardo V. Rodríguez" <evazquez (AT) insys-corp (DOT) com.mx> wrote:
Quote:
But I pretend that automatically when I made an INSERT INTO table (month,
day, time) values (A,B,C) the primary key update his value increasing by
one


I dont know how to do this, Iam using Postgres 7.4 with PgAdminIII
Depending on what you really want sequences might be the solution.
Sequences really only provide you with unique values. If you really need
the values not have any gaps in the numbers then you will need to do
more work (especially if you will be deleting rows).

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster



Reply With Quote
  #5  
Old   
Bruno Wolff III
 
Posts: n/a

Default Re: Primary Key - 06-16-2004 , 02:13 PM



On Mon, Jun 14, 2004 at 19:17:37 -0500,
"Eduardo V. Rodríguez" <evazquez (AT) insys-corp (DOT) com.mx> wrote:
Quote:
But I pretend that automatically when I made an INSERT INTO table (month,
day, time) values (A,B,C) the primary key update his value increasing by one


I dont know how to do this, Iam using Postgres 7.4 with PgAdminIII
Depending on what you really want sequences might be the solution.
Sequences really only provide you with unique values. If you really need
the values not have any gaps in the numbers then you will need to do
more work (especially if you will be deleting rows).

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.