Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGlMS-00GtFr-9y for pgsql-general@arkaria.postgresql.org; Mon, 10 Jun 2024 20:11:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sGlMQ-00Fn66-8q for pgsql-general@arkaria.postgresql.org; Mon, 10 Jun 2024 20:11:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGlMP-00Fn5y-TU for pgsql-general@lists.postgresql.org; Mon, 10 Jun 2024 20:11:22 +0000 Received: from mail.appl-ecosys.com ([50.126.108.78]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGlMK-000gKn-68 for pgsql-general@lists.postgresql.org; Mon, 10 Jun 2024 20:11:21 +0000 Received: from salmo.appl-ecosys.com (salmo.appl-ecosys.com [192.168.55.1]) by mail.appl-ecosys.com (Postfix) with ESMTP id A1CBD2A2B7C for ; Mon, 10 Jun 2024 13:11:14 -0700 (PDT) Date: Mon, 10 Jun 2024 13:11:14 -0700 (PDT) From: Rich Shepard To: pgsql-general@lists.postgresql.org Subject: Re: Multiple tables row insertions from single psql input file In-Reply-To: Message-ID: References: <7da8ec9-089-74ce-eb3-c88889b62c64@appl-ecosys.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8BIT List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 10 Jun 2024, Torsten Förtsch wrote: > Something along these lines perhaps: > > =# create table a( id bigserial primary key, x text ); > CREATE TABLE > =# create table b( fk bigint references a(id), y text ); > CREATE TABLE > =# with ins_a as (insert into a (x) values ('a row') returning *) > insert into b(fk, y) select ins_a.id, 'yy'||i.i from ins_a cross join > generate_series(1,10) as i(i); > INSERT 0 10 > =# table a; table b; > id | x > ----+------- > 1 | a row > (1 row) > > Time: 0.215 ms > fk | y > ----+------ > 1 | yy1 > 1 | yy2 > 1 | yy3 > 1 | yy4 > 1 | yy5 > 1 | yy6 > 1 | yy7 > 1 | yy8 > 1 | yy9 > 1 | yy10 > (10 rows) Torsten, You answered my question. The tables are already created and I'll need to insert new rows table-by-table as I've done before now. Thanks, Rich