Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ojEsa-0005YN-5E for pgsql-sql@arkaria.postgresql.org; Fri, 14 Oct 2022 07:13:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ojEsY-0003Yy-Vw for pgsql-sql@arkaria.postgresql.org; Fri, 14 Oct 2022 07:13:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ojEsY-0003Yp-MG for pgsql-sql@lists.postgresql.org; Fri, 14 Oct 2022 07:13:10 +0000 Received: from mail.familiegard.de ([2a01:4f8:192:1144::88]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ojEsV-0002BE-TP for pgsql-sql@lists.postgresql.org; Fri, 14 Oct 2022 07:13:10 +0000 Received: from [IPV6:2a02:6d40:2143:b901:92f6:52ff:fe00:a664] (unknown [IPv6:2a02:6d40:2143:b901:92f6:52ff:fe00:a664]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: frank@familie-gard.de) by mail.familiegard.de (Postfix) with ESMTPSA id 80BF82A00189 for ; Fri, 14 Oct 2022 09:13:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=familie-gard.de; s=202201; t=1665731586; bh=ysj2U5b0hArFxxzs9I8sHhOB7mbr2n9nV5abvXF+Dj8=; h=Date:Subject:To:References:From:In-Reply-To:From; b=J+Ygrr+cQDKArPv691sdiLVwWk1RQQTTCEEzKfuYQsca9+L3y6UmQYKKpraHPk46K n+H13UYEGTNp++ckBbg8bXlFcUaZRgJx7gIzkNP1JERO+Uc9BUCy6dfHic+yne6N0c kE2dLVkD8Qs/XEE66zNvy7tla0L/w/YSMBsFCOLI= Content-Type: multipart/alternative; boundary="------------5tfyAIUPVVeXOApWLqlRDG4w" Message-ID: Date: Fri, 14 Oct 2022 09:13:05 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Subject: Re: Append a list of tables to an empty table to form a whole table Content-Language: de-DE To: pgsql-sql@lists.postgresql.org References: From: Frank Gard In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------5tfyAIUPVVeXOApWLqlRDG4w Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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:frank@familie-gard.de 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 --------------5tfyAIUPVVeXOApWLqlRDG4w Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

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: frank@familie-gard.de

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.
Siehe http://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
--------------5tfyAIUPVVeXOApWLqlRDG4w--