Home > Enterprise >  How do I increase value of a column variable in postgresql when I select row?
How do I increase value of a column variable in postgresql when I select row?

Time:11-09

I have a table with simple columns - name, gender, age, etc. And I have a column named view_count. By default, it's 0. I need to increase this value on 1 every time when a row is selected.

I need a query something like this:

Select name, age from table_name Limit 1, view_count =1

CodePudding user response:

Use an UPDATE and return the data as it was an SELECT:

UPDATE table_name 
SET view_count = view_count   1
WHERE ? = ? -- some condition or not?
RETURNING name, age; -- proces this like a SELECT statement
  • Related