Search Postgresql Archives

postgres insert + select + values - Pgsql 9.5

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

 



Hi guys,


I got the test1 table with three columns:

id(BIGINT) - j_id(BIGINT) - comments(CHARACTER VARYING)

This needs to be done 180 times:
INSERT INTO test1 (id,j_id,comments) VALUES (default,123321,'test-1 - comments');
INSERT INTO test1 (id,j_id,comments) VALUES (default,123322,'test-1 - comments');
INSERT INTO test1 (id,j_id,comments) VALUES (default,123323,'test-1 - comments');
INSERT INTO test1 (id,j_id,comments) VALUES (default,123324,'test-1 - comments');
INSERT INTO test1 (id,j_id,comments) VALUES (default,123325,'test-1 - comments');

However, I have to get j_id from another table:
select j_id from test2 WHERE customer_id = 88897

17012651
17012601
16623374
16808986
16843879
16808794
16870199
16870488
16870443
16870403 


Example of what I need:

INSERT INTO test1 (id,j_id,comments) VALUES (default, 17012651,'test-1 - comments');
INSERT INTO test1 (id,j_id,comments) VALUES (default, 17012601,'test-1 - comments');
INSERT INTO test1 (id,j_id,comments) VALUES (default, 16623374,'test-1 - comments');
INSERT INTO test1 (id,j_id,comments) VALUES (default, 16808986,'test-1 - comments');
INSERT INTO test1 (id,j_id,comments) VALUES (default, 16843879,'test-1 - comments');

etc...

How can I do that? If the customer_id is the same for all those 180 rows?

Cheers
Patrick

[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