Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Referring to How to insert values into a table from a select query in PostgreSQL?,

I would like to INSERT into a table rows from another, specified by a SELECT DISTINCT, plus some static values, something like:

INSERT INTO new_tbl (column1, column2, column3)
SELECT DISTINCT id FROM -- long where clause --, 
  'a string', 0;

So that every row in the new table will get the same values for column2 and column3 Is this possible?

share|improve this question
up vote 1 down vote accepted

You can put static values into SELECT clause.

INSERT INTO new_tbl (column1, column2, column3)
    SELECT DISTINCT id, 'a string', 0 FROM -- long where clause --;
share|improve this answer
    
facepalm... how on earth was I not seeing this? select query too long ;) – Julian Rubisch Mar 14 at 9:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.