There is a table of 2 columns. I want to fill it with one request. The first column is the values ​​of one column from another table. The second column is a kind of constant.

That is, it is necessary:

  • read the set of values ​​from Table 2
  • combine this with constant
  • insert it in one query in Table 1

Is it possible

Postgresql 9.

    1 answer 1

    Sort of:

    INSERT INTO tb1 (col1_FromTb2, col2_withConstVal) SELECT tb2.val1, 'my_const' FROM tb2 WHERE tb2.field = 'need_val';