0

I'd like to log any table. So I need to know what columns changed. Could you give me some tips for hoping result? I only want updated column.

table: test

col1 |col2 | col3
------+------+------
 a    | a    | a
 b    | b    | b

Query:

UPDATE test SET col2='x' WHERE col1='a'RETURNING *;

result:

 col1 | col2 | col3 
------+------+------
 a    | x    | a

expected result:

| col2 | 
+------+
| x    | 
2
  • 1
    Do you want to build an audit trail ? wiki.postgresql.org/wiki/Audit_trigger Commented Jun 11, 2013 at 9:02
  • Why do you expect a single column when you specify * which means "all columns"? Commented Jul 10, 2015 at 16:07

1 Answer 1

3

Returning * works much like a select statement. You can specify column names, e.g. returning col2.

Also, note Marcello's comment: audits are better done using triggers.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.