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 1gT6I0-00028I-H5 for pgsql-general@arkaria.postgresql.org; Sat, 01 Dec 2018 14:30:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gT6Hx-0001AB-RR for pgsql-general@arkaria.postgresql.org; Sat, 01 Dec 2018 14:30:33 +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 1gT6Hx-00019u-JZ for pgsql-general@lists.postgresql.org; Sat, 01 Dec 2018 14:30:33 +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 1gT6Hs-0007Lb-6o for pgsql-general@postgresql.org; Sat, 01 Dec 2018 14:30:31 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 10BE021F47; Sat, 1 Dec 2018 09:30:26 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Sat, 01 Dec 2018 09:30:26 -0500 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=fm1; bh=a fqiPLL60yOS5AHde/lgpc16ZoiXzdYwqJLJadQ/J4E=; b=WidZbYcxaHGCAi7gy oREd0CqXsLneFiyosJ0mduSwum/E4h9ba3MiR7lHMSg9tWAZ4xYXOBvS/bl41NM4 yoa892o2sHXMVzCkXkUnDSU8l/lc6wxyS9ZUHdvOjh0rHuvsWeWxvTNMoZZsuzD8 RvyjuS87Ro7LuEIKYZM02FRwVfiQGX4Xriqv630c4F0wNNSRHKW1/xhvyAQNQ7XB RjyYP4i7VQz8C5A4vivWmpXEVEIab5jIA3iKiu34enIPQ13Z8+/cxUFW92/NZj+0 kq/2hCdZvmHBA2BlA0aOGceNQ248qCBoiQIWaXuUYaRe8tge8jAiO3Gfn8fRtHol g04ng== 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=fm1; bh=afqiPLL60yOS5AHde/lgpc16ZoiXzdYwqJLJadQ/J 4E=; b=csf5VoFNYAVL9UaOAl1vKY5djhFcP46QaIVrPGxoG/wXRJgNP75Br05HO f56dDiSd/hI6uiwul/12Yo324bJdXP1fT2pKCcjLeTFQ34PrlRJ6X0MGqHtjhCwQ BS0g1EOYIOq0fPszrXgbLJUQLNDOBTvpF9ZobmVQfnmRFNlIQTrBn05p9rTYDZo7 PvDOPJwFJd4fD9nZ0176RHdjFdCyLHzwikiTH84tKPJKekRm4YTbugCcbKX+Thfo fvrrXvNE0FdmOFDo9wBewYPfq/0XiwFPOq0CmN/WCk0dudElhIAczbnqD9wZldAA 7XK1qEd8BVuvbgUmD45EwsFMobKGg== X-ME-Sender: X-ME-Proxy: Received: from [192.168.1.3] (unknown [71.212.134.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 1884CE4443; Sat, 1 Dec 2018 09:30:25 -0500 (EST) Subject: Re: Process for populating tables in new database To: Rich Shepard , pgsql-general@postgresql.org References: From: Adrian Klaver Message-ID: <46b7813b-9c5c-c98f-8895-88bc4de635e7@aklaver.com> Date: Sat, 1 Dec 2018 06:30:24 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 12/1/18 6:09 AM, Rich Shepard wrote: > I have a new database with five tables, and text files with data to > populate > the tables using the insert command. > > 1. Each table has a sequential primary key. Should I manually add keys to > each insert row or will postgres generate it automatically? Example, for > the > companies table: If you don't supply the key it will be generated as the default for the PK column is a sequence. > > org_id    | integer               |           | not null | > nextval('companies_org_id_seq'::regclass) > org_name  | character varying(64) |           | not null | > > 2. Should I use sepatate files as input to each table or can I combine them > in a single file? For example, adding a company name and contact name for > someone in that company using input commands for both tables in a single > file? I will need to provide the primary key to the company table as the > foreign key in contact table and have not before pupulated multiple related > tables in a new database from .sql files. So are the tables you are INSERTing into currently unpopulated? In any case you will need to do this in sequence, where you populate the company table and then the contact table. The question is whether you want to pre-assign the company id's in the company data and the company_id_fk in the contacts data or not. If not then you will need to grab the company id's after populating the company table and match those to the contacts data before inserting it. > > TIA, > > Rich > > > > > > -- Adrian Klaver adrian.klaver@aklaver.com