Thread: Auto incrementing an integer
How do I construct a datatype that autoincrement in postgreSQL? Thanks Sylte
Quoting Sylte <Sylte_@hotmail.com>: > How do I construct a datatype that autoincrement in postgreSQL? See sequences and the SERIAL type. Saludos... :-) -- El mejor sistema operativo es aquel que te da de comer. Cuida tu dieta. ----------------------------------------------------------------- Martin Marques | mmarques@unl.edu.ar Programador, Administrador | Centro de Telematica Universidad Nacional del Litoral -----------------------------------------------------------------
Take a look at the SERIAL datatype as well as sequences (CREATE SEQUENCE, NEXTVAL, CURRVAL). good luck! On Mon, 14 May 2001, Sylte wrote: > How do I construct a datatype that autoincrement in postgreSQL? > > Thanks > Sylte > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) >
Try the serial data type or add "DEFAULT nextval('Invoice_s')" to the column definition where Invoice_s is the name of a sequence that you have created. Hope this helps, Michael -----Original Message----- From: Sylte [SMTP:Sylte_@hotmail.com] Sent: Monday, May 14, 2001 7:02 AM To: pgsql-sql@postgresql.org Subject: Auto incrementing an integer How do I construct a datatype that autoincrement in postgreSQL? Thanks Sylte ---------------------------(end of broadcast)--------------------------- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
is there any function from which i can get system time? ____________________________________________________________ Do You Yahoo!? Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk or your free @yahoo.ie address at http://mail.yahoo.ie
select now(); ??? + Justin Seema Noor wrote: > > is there any function from which i can get system time? > > ____________________________________________________________ > Do You Yahoo!? > Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk > or your free @yahoo.ie address at http://mail.yahoo.ie > > ---------------------------(end of broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org -- "My grandfather once told me that there are two kinds of people: those who work and those who take the credit. He told me to try to be in the first group; there was less competition there." - Indira Gandhi
Try using: SELECT now() It should do what you want. If not there are a whole pile of date functions. Look them up in the Users Guide. Hope this is helpful. Jason --- Seema Noor <seema_56@yahoo.com> wrote: > is there any function from which i can get system > time? > > ____________________________________________________________ > Do You Yahoo!? > Get your free @yahoo.co.uk address at > http://mail.yahoo.co.uk > or your free @yahoo.ie address at > http://mail.yahoo.ie > > ---------------------------(end of > broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org __________________________________________________ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/
Sylte wrote: >How do I construct a datatype that autoincrement in postgreSQL? > Use the SERIAL data type instead of an INT4. Serial is an integer (INT4) that's default value is base on a sequence. for example... create table foo ( my_id serial not null, my_data text );
Thanks Mart�n....I found this http://dis.lib.muohio.edu/code/entry.html?ID=3 Creating an Autoincrement field in Postgresql postgres does this a little differently; the "serial" type creates an integer column, and a sequence used to increment this column. try this: create table table_name(control serial,another_column text,primary key(control) ); results in this: Table = table_name +----------------------------------+----------------------------------+----- --+ | Field | Type | Length| +----------------------------------+----------------------------------+----- --+ | control | int4 not null default nextval('" | 4 | | another_column | text | var | +----------------------------------+----------------------------------+----- --+ Index: table_name_pkey