Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update column value PostgreSQL

Tags:

sql

postgresql

I am trying to update the value of a column where it matches a certain userid, but it keeps giving a syntax error.

UPDATE user 
   SET balance = 15000.000000000 
 WHERE id = 11203;

The table called user has many rows with two columns, balance and id. I am trying to edit the balance of the user id in the code.

like image 619
user1449384 Avatar asked Jul 02 '12 20:07

user1449384


People also ask

How do I change the value of a column in Postgres?

Syntax. UPDATE table_name SET column1 = value1, column2 = value2...., columnN = valueN WHERE [condition];

How do you update value in Pgadmin?

To change a numeric value within the grid, double-click the value to select the field. Modify the content in the square in which it is displayed. To change a non-numeric value within the grid, double-click the content to access the edit bubble.

How do you update an existing column?

First, specify the table name that you want to change data in the UPDATE clause. Second, assign a new value for the column that you want to update. In case you want to update data in multiple columns, each column = value pair is separated by a comma (,). Third, specify which rows you want to update in the WHERE clause.

How Update works in Postgres?

PostgreSQL implements multiversioning by keeping the old version of the table row in the table – an UPDATE adds a new row version (“tuple”) of the row and marks the old version as invalid. In many respects, an UPDATE in PostgreSQL is not much different from a DELETE followed by an INSERT .


2 Answers

Try "user", or give a more generic name:

UPDATE "user" 
 SET balance = 15000.000000000 
 WHERE id = 11203;

or ALTER your table name to "user_list" for example. Any doubt, please check keywords

like image 100
cybertextron Avatar answered Oct 19 '22 23:10

cybertextron


You need to escape user since it is a reserved word. Try

UPDATE "user"
SET balance = 15000.000000000 
WHERE id = 11203;
like image 18
juergen d Avatar answered Oct 19 '22 23:10

juergen d