2

How to add results of selecting query to a new column in already existing table in PostgreSQL in pgAdmin?

Results of the select query is an alteration of over columns in the same table.

2
  • 3
    Please Edit your question and add some sample data and the expected output based on that data. Formatted text please, no screen shots Commented Jan 13, 2017 at 12:35
  • 1
    try something like this with new_table as ( SELECT id, col1-col2 as diff from yourtable ) update yourtable as yt set time_diff = yt.diff from new_table yt where yt.id = tr.id; Commented Jan 13, 2017 at 12:35

1 Answer 1

1

Just create the column and update data afterwards (using the command line bundled in pgadmin):

ALTER TABLE tablename ADD COLUMN colname coltype;
UPDATE tablename SET colname = yourexpression;
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, had the same thing, just had a problem with column name

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.