Search Postgresql Archives

Re: postgres insert + select + values - Pgsql 9.5

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 16/09/16 08:07, Patrick B wrote:
> 
> 
>     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
>     <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
> 

If your select returns 180 rows, then an `insert into select` query
would insert 180 rows (assuming other constraints like primary / unique
keys are met).

-- 
Postgresql & php tutorials
http://www.designmagick.com/



-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux