Re: postgres insert + select + values - Pgsql 9.5
От
Lucas Possamai
Тема
Re: postgres insert + select + values - Pgsql 9.5
Дата
Msg-id
CAE_gQfW=vbtf49MiSWBaGVA8W3uosBLDecqAXdwNw4R+i15RKA@mail.gmail.com
Ответ на
Список
Дерево обсуждения
postgres insert + select + values - Pgsql 9.5 Patrick B <patrickbakerbr@gmail.com>
Re: postgres insert + select + values - Pgsql 9.5 Chris <dmagick@gmail.com>
Re: postgres insert + select + values - Pgsql 9.5 Patrick B <patrickbakerbr@gmail.com>
Re: postgres insert + select + values - Pgsql 9.5 Chris <dmagick@gmail.com>
Re: postgres insert + select + values - Pgsql 9.5 Lucas Possamai <drum.lucas@gmail.com>
Re: postgres insert + select + values - Pgsql 9.5 Patrick B <patrickbakerbr@gmail.com>
2016-09-16 10:07 GMT+12:00 Patrick B <patrickbakerbr@gmail.com>:
A select can make up columns too, not just what you've got in a table,
so you can:
select j_id, 'test-1 - comments' as comment from test2 where
customer_id=88897;
and then you can simply insert that into your other table (you don't
need to specify the columns that are getting a default value):
insert into test1 (j_id, comments)
select j_id, 'test-1 - comments' as comment from test2 where
customer_id=88897;
https://www.postgresql.org/docs/current/static/sql-insert. html has more
info.Thanks Chris!But the problem is that test2 table has 180 rows with different j_id and I need to insert each one of them into test1 table.How can I do that?select j_id FROM test2 - will return 180 rows
Please have a look on this example Patrick: http://sqlfiddle.com/#!15/1773d/4
Lucas
В списке pgsql-general по дате отправления