pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rich Shepard <rshepard@appl-ecosys.com>
To: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Bulk inserts into two (related) tables
Date: Wed, 22 May 2019 12:24:44 -0700 (PDT)
Message-ID: <alpine.LNX.2.20.1905221218100.1484@salmo.appl-ecosys.com> (raw)
In-Reply-To: <a29a695e-acba-37f0-e73e-8d71dd4385de@aklaver.com>
References: <alpine.LNX.2.20.1905210945100.6551@salmo.appl-ecosys.com>
	<CA+bJJbyAsgWaxHvMBz3kTxWcekwGPv3yLXbKO4Yixgj5td25KQ@mail.gmail.com>
	<alpine.LNX.2.20.1905211022360.6551@salmo.appl-ecosys.com>
	<CA+bJJbwjTGmnTw55gvjbeNfutPY1Z-PsXoz_f7ycLDGac2SPxA@mail.gmail.com>
	<alpine.LNX.2.20.1905220535340.1484@salmo.appl-ecosys.com>
	<CAMa1XUgOeJ-TGX7DX-RrEzZUhdyLLykC6p+GFm70DeX6x9RavQ@mail.gmail.com>
	<alpine.LNX.2.20.1905220725100.1484@salmo.appl-ecosys.com>
	<CA+bJJbxkuX0=t8zyd2TV6Gf6xL1qXhLXstBm_koq63a7aK=i3w@mail.gmail.com>
	<alpine.LNX.2.20.1905220857540.1484@salmo.appl-ecosys.com>
	<CA+bJJbw5NxSE=hAKmT03RpOqdFuDDSvnzah7GpSxJU7ST8fjOA@mail.gmail.com>
	<alpine.LNX.2.20.1905221039260.1484@salmo.appl-ecosys.com>
	<a29a695e-acba-37f0-e73e-8d71dd4385de@aklaver.com>

On Wed, 22 May 2019, Adrian Klaver wrote:

> A sample of the data you are cleaning up.

Adrian, et al.:

I have it working properly now. Both org_id and person_id numbers are
prepended to each row in the appropriate table and they are unique because
each series begins one greater than the max(*_id) in each table.

> I think what people are trying to wrap there head around is how 800 lines
> in the file is being split into two subsets: the organization data and the
> people data. In particular how that is being done to preserve the
> relationship between organizations and people? This is before it ever gets
> to the database.

After cleaning there are 655 lines rather than 800, but the short answer is
that spliting the data preserves the relationship between organization and
its people:

#!/usr/bin/gawk

# Read input file, write fields to both organizations and people
# input files.

BEGIN { FS=OFS="," }
# for organizations table input:
{ print $1, $2, $4, "," $8, $9, $10, "'US'," $11, ",,," "'Opportunity','');" > "z-orgs.sql" }
# for people table input:
{ print $6, $5, "," $1, $3, $4, $5, $7, $8, $9, $10, "'US'," $11, "," $12, "," $13, "'true','');" > "z-people.sql" }

You can see that the org_id field ($1) is used in both files, but in
different columns in the two tables.

Regards,

Rich







view thread (32+ messages)

Message-ID: <alpine.LNX.2.20.1905221218100.1484@salmo.appl-ecosys.com>
Permalink:  ../alpine.LNX.2.20.1905221218100.1484@salmo.appl-ecosys.com/
Also on:    postgresql.org/message-id/alpine.LNX.2.20.1905221218100.1484@salmo.appl-ecosys.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: rshepard@appl-ecosys.com
  Subject: Re: Bulk inserts into two (related) tables
  In-Reply-To: <alpine.LNX.2.20.1905221218100.1484@salmo.appl-ecosys.com>
  References: <alpine.LNX.2.20.1905210945100.6551@salmo.appl-ecosys.com> <CA+bJJbyAsgWaxHvMBz3kTxWcekwGPv3yLXbKO4Yixgj5td25KQ@mail.gmail.com> <alpine.LNX.2.20.1905211022360.6551@salmo.appl-ecosys.com> <CA+bJJbwjTGmnTw55gvjbeNfutPY1Z-PsXoz_f7ycLDGac2SPxA@mail.gmail.com> <alpine.LNX.2.20.1905220535340.1484@salmo.appl-ecosys.com> <CAMa1XUgOeJ-TGX7DX-RrEzZUhdyLLykC6p+GFm70DeX6x9RavQ@mail.gmail.com> <alpine.LNX.2.20.1905220725100.1484@salmo.appl-ecosys.com> <CA+bJJbxkuX0=t8zyd2TV6Gf6xL1qXhLXstBm_koq63a7aK=i3w@mail.gmail.com> <alpine.LNX.2.20.1905220857540.1484@salmo.appl-ecosys.com> <CA+bJJbw5NxSE=hAKmT03RpOqdFuDDSvnzah7GpSxJU7ST8fjOA@mail.gmail.com> <alpine.LNX.2.20.1905221039260.1484@salmo.appl-ecosys.com> <a29a695e-acba-37f0-e73e-8d71dd4385de@aklaver.com> <alpine.LNX.2.20.1905221218100.1484@salmo.appl-ecosys.com>

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

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