public inbox for [email protected]  
help / color / mirror / Atom feed
Append a list of tables to an empty table to form a whole table
3+ messages / 2 participants
[nested] [flat]

* Append a list of tables to an empty table to form a whole table
@ 2022-10-14 06:00  Shaozhong SHI <[email protected]>
  0 siblings, 1 reply; 3+ messages in thread

From: Shaozhong SHI @ 2022-10-14 06:00 UTC (permalink / raw)
  To: pgsql-sql <[email protected]>

How best to append a list of tables to an empty table to form a whole table?

Pseudo codes show the desirable logic.



There are a list of tables with exactly same colums
table_a
table_b
table_c

Create an empty table  emp_table

Foreach a_name in ARRAY ARRAY['table_a', 'table_b', 'table_c'] loop
   insert into em_table as select * from table a_name

end loop;

Can something like that be done is PostGIS?

Regards,

David


^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Append a list of tables to an empty table to form a whole table
@ 2022-10-14 07:13  Frank Gard <[email protected]>
  parent: Shaozhong SHI <[email protected]>
  0 siblings, 1 reply; 3+ messages in thread

From: Frank Gard @ 2022-10-14 07:13 UTC (permalink / raw)
  To: [email protected]

Hi,

again: Use EXECUTE! It's well documented here: https://www.postgresql.org/docs/15/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN

In your case, you can simply replace your INSERT statement by the following:

     EXECUTE 'insert into em_table as select * from table ' || a_name;

Hope this helps.

Frank.

Am 14.10.22 um 08:00 schrieb Shaozhong SHI:
>
>
> How best to append a list of tables to an empty table to form a whole table?
>
> Pseudo codes show the desirable logic.
>
>
>
> There are a list of tables with exactly same colums
> table_a
> table_b
> table_c
>
> Create an empty table  emp_table
>
> Foreach a_name in ARRAY ARRAY['table_a', 'table_b', 'table_c'] loop
>    insert into em_table as select * from table a_name
>
> end loop;
>
> Can something like that be done is PostGIS?
>
> Regards,
>
> David

-- 
Vielen Dank und viele Grüße,

Frank Gard
Zum Brünnchen 27
D-66583 Spiesen-Elversberg
Tel. : +49(6821)790880
E-Mail:[email protected]

Bitte denken Sie über Ihre Verantwortung gegenüber der Umwelt nach,
bevor Sie diese Mail ausdrucken.

Bitte senden Sie mir keine Word-, Excel- oder PowerPoint-Anhänge.
Siehehttp://www.gnu.org/philosophy/no-word-attachments.de.html

GnuPG / PGP info
================
Schlüssel-ID: 0xC8C1A552
Fingerabdruck / fingerprint:
3EFD EF94 4841 38B5 DB40 95D8 C69C 71C5 C8C1 A552


^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Append a list of tables to an empty table to form a whole table
@ 2022-10-14 08:50  Frank Gard <[email protected]>
  parent: Frank Gard <[email protected]>
  0 siblings, 0 replies; 3+ messages in thread

From: Frank Gard @ 2022-10-14 08:50 UTC (permalink / raw)
  To: [email protected]

Sorry,

c&p-error (was in hurry this morning). Omit "as" and "table", please:

     EXECUTE 'insert into em_table select * from ' || a_name;

Frank.

Am 14.10.22 um 09:13 schrieb Frank Gard:
>
> Hi,
>
> again: Use EXECUTE! It's well documented here: https://www.postgresql.org/docs/15/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN
>
> In your case, you can simply replace your INSERT statement by the following:
>
>     EXECUTE 'insert into em_table as select * from table ' || a_name;
>
> Hope this helps.
>
> Frank.
>
> Am 14.10.22 um 08:00 schrieb Shaozhong SHI:
>>
>>
>> How best to append a list of tables to an empty table to form a whole table?
>>
>> Pseudo codes show the desirable logic.
>>
>>
>>
>> There are a list of tables with exactly same colums
>> table_a
>> table_b
>> table_c
>>
>> Create an empty table  emp_table
>>
>> Foreach a_name in ARRAY ARRAY['table_a', 'table_b', 'table_c'] loop
>>    insert into em_table as select * from table a_name
>>
>> end loop;
>>
>> Can something like that be done is PostGIS?
>>
>> Regards,
>>
>> David
> -- 
> Vielen Dank und viele Grüße,
>
> Frank Gard
> Zum Brünnchen 27
> D-66583 Spiesen-Elversberg
> Tel. : +49(6821)790880
> E-Mail:[email protected]
>
> Bitte denken Sie über Ihre Verantwortung gegenüber der Umwelt nach,
> bevor Sie diese Mail ausdrucken.
>
> Bitte senden Sie mir keine Word-, Excel- oder PowerPoint-Anhänge.
> Siehehttp://www.gnu.org/philosophy/no-word-attachments.de.html
>
> GnuPG / PGP info
> ================
> Schlüssel-ID: 0xC8C1A552
> Fingerabdruck / fingerprint:
> 3EFD EF94 4841 38B5 DB40 95D8 C69C 71C5 C8C1 A552

-- 
Vielen Dank und viele Grüße,

Frank Gard
Zum Brünnchen 27
D-66583 Spiesen-Elversberg
Tel. : +49(6821)790880
E-Mail:[email protected]

Bitte denken Sie über Ihre Verantwortung gegenüber der Umwelt nach,
bevor Sie diese Mail ausdrucken.

Bitte senden Sie mir keine Word-, Excel- oder PowerPoint-Anhänge.
Siehehttp://www.gnu.org/philosophy/no-word-attachments.de.html

GnuPG / PGP info
================
Schlüssel-ID: 0xC8C1A552
Fingerabdruck / fingerprint:
3EFD EF94 4841 38B5 DB40 95D8 C69C 71C5 C8C1 A552


^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2022-10-14 08:50 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-10-14 06:00 Append a list of tables to an empty table to form a whole table Shaozhong SHI <[email protected]>
2022-10-14 07:13 ` Frank Gard <[email protected]>
2022-10-14 08:50   ` Frank Gard <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox