public inbox for [email protected]  
help / color / mirror / Atom feed
From: Rich Shepard <[email protected]>
To: [email protected]
Subject: Re: Multiple tables row insertions from single psql input file
Date: Mon, 10 Jun 2024 13:11:14 -0700 (PDT)
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAKkG4_mjjPcWJYhqs4VboSrMJno4t1mtOZLvppy-W3edA=Jzew@mail.gmail.com>
References: <[email protected]>
	<CAKkG4_mjjPcWJYhqs4VboSrMJno4t1mtOZLvppy-W3edA=Jzew@mail.gmail.com>

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






view thread (2+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Multiple tables row insertions from single psql input file
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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