Re: postgres insert + select + values - Pgsql 9.5

From: Patrick B <patrickbakerbr(at)gmail(dot)com>
To: Chris <dmagick(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: postgres insert + select + values - Pgsql 9.5
Date: 2016-09-15 22:07:42
Message-ID: CAJNY3ivJtvzuS07u7yupmVg0+gPv6aRb7EunA9M3dH8dei8eiQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>
>
>
> 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Lucas Possamai 2016-09-15 22:16:57 Re: postgres insert + select + values - Pgsql 9.5
Previous Message Chris 2016-09-15 22:00:05 Re: postgres insert + select + values - Pgsql 9.5