Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hTTmE-0000qB-Hj for pgsql-general@arkaria.postgresql.org; Wed, 22 May 2019 16:07:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hTTmD-0006w4-9i for pgsql-general@arkaria.postgresql.org; Wed, 22 May 2019 16:07:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hTTmC-0006sb-TH for pgsql-general@lists.postgresql.org; Wed, 22 May 2019 16:07:36 +0000 Received: from mail.appl-ecosys.com ([50.126.108.78]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hTTm7-0006e5-IT for pgsql-general@lists.postgresql.org; Wed, 22 May 2019 16:07:36 +0000 Received: from salmo.appl-ecosys.com (salmo.appl-ecosys.com [192.168.55.1]) by mail.appl-ecosys.com (Postfix) with ESMTP id 454E099387 for ; Wed, 22 May 2019 09:07:29 -0700 (PDT) Date: Wed, 22 May 2019 09:07:29 -0700 (PDT) From: Rich Shepard To: "pgsql-generallists.postgresql.org" Subject: Re: Bulk inserts into two (related) tables In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (LNX 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, 22 May 2019, Francisco Olarte wrote: > You are not reading what we write to you. Note YOU AND ONLY YOU are the > one speaking of PK. We are speaking of "unique identifier" ( that would > be, IIRC, "candidate keys", you can peek any as your PK, or even introduce > a new synthetic one with a sequence, or a femto second exact timestamp or > whatever ). Francisco, Let me clarify. The organizations table has org_id (an integer) as PK. The people table has person_id (an interger) as PK and org_id as the reference to organization.org_id. Does this help? > When you are fluent in SQL you do not try to play with files, you import > every column of your data into temporary tables, clean them up, and join ( > if needed ) them until you have a select that gives you what you want and > then insert this. Normally you insert several SELECTS into temporary > tables ( specially when you only have thousands of records ) so you can do > the clean up in steps. Most of my time is spent writing using LaTeX/LyX. Depending on the project's needs I'll also use SQL, R, GRASS, and other tools. I'm a generalist, like your PCP, not a specialist. But, I also rely on emacs, grep, sed, and awk for data munging and am more fluent with these tools than I am with SQL or Python. For me, the quickest and simplest appoach is to add the PKs to each table, and the org_id into the people table, when I separate the cleaned text file into the columns for each table. Regards, Rich