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 1hTWcV-0000zB-2G for pgsql-general@arkaria.postgresql.org; Wed, 22 May 2019 19:09:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hTWcT-0005Of-TB for pgsql-general@arkaria.postgresql.org; Wed, 22 May 2019 19:09:45 +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 1hTWcS-0005OY-Pv for pgsql-general@lists.postgresql.org; Wed, 22 May 2019 19:09:45 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hTWcP-0002NT-7n for pgsql-general@lists.postgresql.org; Wed, 22 May 2019 19:09:44 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id ECC972448F; Wed, 22 May 2019 15:09:39 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Wed, 22 May 2019 15:09:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=S w6WvGhy/tdQxVje0ylNynvv4iQ6y1yNroKdOHQSsWY=; b=kDzQZ5ni8o4TpxH0D GeQrkR7DXEYgQFvN2J+lAuNtVNn8lzOx4/Ee9JH6w8yRw+TYqlrAymc2V6QvS9qR 9jFQuydPEy75UJgk+tTMPkjH8Fz6QofepXjEjd41OXF7NcEgszCDLPJTutQZXAYr PpZI3XbgDbdPBHownDa/2coAM6bOMrYG2iaW2PS4enQ76fjTYbTk2xojQpnyCPY5 zaAwjAo9etuv4wrO9iJEXlHRk/qQAU4V0Zi1ryqiLG59FQOfzxFzYSXMW2b9U7IE 9QnHcklIBzpTaqlqc5IX5OAHPpStFOZIS48FhnIPrjzG9nE14DFMRXrHolDJH7PP mEOcA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=Sw6WvGhy/tdQxVje0ylNynvv4iQ6y1yNroKdOHQSs WY=; b=CyNKPFivdDSIejui2y1Y2qzyxLi5C4b5c4mVuCIfLrc2XXTFrF+Ql0NF9 8BgzkESws1Dzk1xwIp9BXv+GAjkmlQm1XfY+kXs8pGkl0tCYWGpQCyJvVCoklJYS WehpwAC1bU7Ch2VLnxI47oYWiqUfLfSyGh/q73f6LB5RgAoqVfzbJ9Do2H0GME8A TObiSX5QZmXTYdb9Sac5wcrCO7r0FAnBV8Jr7mbGSD18FMJTFmumKueGmxv/rfwE U1PMT8g/yz1kPtyeeUNeWGiig2HGCWeL6M+ZtxUU3tqug+GI4dhNDIfS1m37OFPi vLHxHaQLe7lpD4V56xjcq/STLQIyQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrudduvddgudefhecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefuvfhfhffkffgfgggjtgfgsehtjeertddtfeejnecuhfhrohhmpeetughr ihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtg homheqnecuffhomhgrihhnpehssheigedrtghomhenucfkphepjedurddvuddvrdduhedt rddvtddvnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrse grkhhlrghvvghrrdgtohhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from [192.168.1.4] (unknown [71.212.150.202]) by mail.messagingengine.com (Postfix) with ESMTPA id 06B3E380085; Wed, 22 May 2019 15:09:38 -0400 (EDT) Subject: Re: Bulk inserts into two (related) tables To: Rich Shepard , "pgsql-generallists.postgresql.org" References: From: Adrian Klaver Message-ID: Date: Wed, 22 May 2019 12:09:38 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 5/22/19 10:53 AM, Rich Shepard wrote: > On Wed, 22 May 2019, Francisco Olarte wrote: > >> Also, when I speak of "unique identifier" I'm not speaking of the one if >> your FINAL tables, I assume you would have at least the *_id field as >> PKEY, so nothing else needed, but the one in your SOURCE data set (it can >> be anything, like the row number in the original excel). > > Francisco/Jeremy, > > I'm grateful for you patient help. The 'unique identifier' in the source > file has been provided (just now) using nl . > The syntax I used is: > > nl -b a -n ln -s , -v 339 source.txt > out.txt > > because the organizations table has 338 as the maximum org_id number. > > I believe this fulfills the need for a known unique ID in the source file, > and when I parse each row using gawk to create the two files for table > input > I can use it in both the organizations table (as the PK) and the people > table (as the FK referring to the organizations table). I can let postgres > assign the unique ID for the new rows in the people table. > > Am I still missing something critical? A sample of the data you are cleaning up. 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. > >> MMM, apart from angel dust I do not know what PCP could stand for. > > Primary Care Physician. > > Best regards, > > Rich > > > > -- Adrian Klaver adrian.klaver@aklaver.com