Skip site navigation (1) Skip section navigation (2)

Re: question re incrementing an integer field in a table.

From: Thom Brown <thom(at)linux(dot)com>
To: richard terry <rterry(at)internode(dot)on(dot)net>
Cc: PostgreSQL Novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: question re incrementing an integer field in a table.
Date: 2011-12-16 11:09:05
Message-ID: CAA-aLv4TdHdwtR=ctijtv+P=mgre0iSwxCL3MuZ2Bthd_EpF7g@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
On 16 December 2011 10:57, richard terry <rterry(at)internode(dot)on(dot)net> wrote:
> Hope this question isn't too idiotic and makes sense.
>
>
> Is there a simple way to increment the value of an integer field in a table in
> sql  without reading the fields value  adding 1 and re-saving? (the field is not
> a primary key or any other sort of foreign key)

Hi,

You will either want to create a column with the pseudo type "serial"
or create a sequence and set the default value of an existing integer
column to use that sequence.  See the documentation:
http://www.postgresql.org/docs/current/static/datatype-numeric.html#DATATYPE-SERIAL

Regards

Thom

In response to

pgsql-novice by date

Next:From: Thomas KellererDate: 2011-12-16 11:24:56
Subject: Re: question re incrementing an integer field in a table.
Previous:From: richard terryDate: 2011-12-16 10:57:40
Subject: question re incrementing an integer field in a table.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group