Обсуждение: question re incrementing an integer field in a table.

Поиск
Список
Период
Сортировка

question re incrementing an integer field in a table.

От
richard terry
Дата:
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)

regards

richard


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

От
Thom Brown
Дата:
On 16 December 2011 10:57, richard terry <rterry@internode.on.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

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

От
Thomas Kellerer
Дата:
richard terry, 16.12.2011 11:57:
> 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)
>

Not sure I understand you question, but are you maybe looking for:

update the_table
   set the_column = the_column + 1;


Thomas

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

От
Aleksej Trofimov
Дата:
On 12/16/2011 12:57 PM, richard terry 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)
>
> regards
>
> richard
>
>
Try this

UPDATE tables SET inc=inc+1 WHERE key=ID;


--
Best regards

Aleksej Trofimov