Postgres: update all values ​​in a column by one?

Is there any way to do this? I assume the following will not work.

Table UPDATE SET column = column + 1 ...

Besides writing a function or using PHP, is there a way to do this with the request?

+5
source share
2 answers

Have you tried It should just work.

+10
source

It will work:

# psql -U postgres
psql (9.0.1)
Type "help" for help.

postgres=# create database test;
CREATE DATABASE
postgres=# \c test
You are now connected to database "test".
test=# create table test (test integer);
CREATE TABLE
test=# insert into test values (1);
INSERT 0 1
test=# insert into test values (2);
INSERT 0 1
test=# select * from test;
 test 
------
    1
    2
(2 rows)

test=# update test set test = test + 1;
UPDATE 2
test=# select * from test;
 test 
------
    2
    3
(2 rows)
+3
source

All Articles