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 1hT9A3-0002dz-OC for pgsql-general@arkaria.postgresql.org; Tue, 21 May 2019 18:06:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hT9A2-0004dP-F0 for pgsql-general@arkaria.postgresql.org; Tue, 21 May 2019 18:06:50 +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 1hT9A2-0004dI-5G for pgsql-general@lists.postgresql.org; Tue, 21 May 2019 18:06:50 +0000 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hT9A0-0005vi-6J for pgsql-general@lists.postgresql.org; Tue, 21 May 2019 18:06:49 +0000 Received: by mail-ot1-x341.google.com with SMTP id c3so17224630otr.3 for ; Tue, 21 May 2019 11:06:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=x2vcWAX9hSrDacRD/sXTr/4bK7d8ndSpdD3B7gxrdBU=; b=bLqUk5o5qZX57OaF2f4mHF/kXyOA9uYB6MIpCeNSr5rPZsEOKyhTz44sSytGHCOO2X Wrb/x70+OSQ0zelXKbDZXrHRIYE+SBFwLxsT7T8HebtuDMTzUcCs1vuEVlnsdt4900BU tuO0yfT9gCIjJmDP3cd/StnMgXKfyIu/kUOr75RvHCRnukHiC8wNnVQNlFFoYFXw69Y/ pMdU6OZeY/KbsFNejJ5AnnPRjDpW7a4iDKEcdmZD83Jtpe60SXQ4nIODXH/kbfPs5Bv5 ogEBtoohltdq6efUDaRdxr6mLKA0GMOzmZQNhBykdrfHdNMRHlpnsOc2Ttxp77pN7TUb TU+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=x2vcWAX9hSrDacRD/sXTr/4bK7d8ndSpdD3B7gxrdBU=; b=hljutoVYF5QWWcW4UcrWz/Ksp4nmzeslkLG1j1mmhBD7hz+ikgoMAyT5kQxMOXkuX+ g7FmZrSESNnj/p/f2LEHw7brrtznbKYyOBwzv0rLwEigAB5YwXrLm1PDwR4QAyKwmsJP M8kgJbUZu9h0C5VuU+KjpkJgcy5BtV/n2CEXOmwiyYla418b0BO0n3NMLs4y0PSfcyVr DBLG/c/3IZaUQx2c/QB3/vuxhg/q1GJYlW3o1BypE7ND1nUeuP+gof8Y7EXfMzPmzjgn 1bxyFqjomxg84/tW6pJo4f/52WUkBIKqY00EGXBaRHgsgJ/5qJp1DkS2s8KHMrmjWcnA 2LoA== X-Gm-Message-State: APjAAAVEuOPPOYIqnBlMpX8g1JRRQlCu4Thh4dn0OqqBNcywotmGJXuV atrIbBU5qd2llxiuFmxGmkwiw6wntT3jdg== X-Google-Smtp-Source: APXvYqzr1JwRGFTaxRj7SgrC6bXy7w/LgWlkhmbGiwssTC6s21Aq4QfEHvsklG/tAP20I8mM/Q11+w== X-Received: by 2002:a9d:3f37:: with SMTP id m52mr16113877otc.181.1558462005711; Tue, 21 May 2019 11:06:45 -0700 (PDT) Received: from [192.168.1.10] (ip70-171-116-89.no.no.cox.net. [70.171.116.89]) by smtp.googlemail.com with ESMTPSA id 5sm1918845ots.22.2019.05.21.11.06.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 May 2019 11:06:44 -0700 (PDT) Subject: Re: Bulk inserts into two (related) tables To: pgsql-general@lists.postgresql.org References: From: Ron Message-ID: Date: Tue, 21 May 2019 13:06:43 -0500 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-Transfer-Encoding: 7bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 5/21/19 12:27 PM, Rich Shepard wrote: > On Tue, 21 May 2019, Michael Lewis wrote: > >> For each row- >> Insert into organizations table if the record does not exist, returning ID. >> Insert into people using that ID. > > Michael, > > The org_id will not exist until I run the insert script. > >> Else, load all the data with empty ID column on person table,then just >> update the person table afterward and drop the org name column. > > Then I'll copy the org_id numbers to the appropriate row(s) in the people > table. A Perl/Python/etc script would solve your problem. -- Angular momentum makes the world go 'round.