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 1gT6RI-0002WX-TH for pgsql-general@arkaria.postgresql.org; Sat, 01 Dec 2018 14:40:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gT6RH-0002SD-Df for pgsql-general@arkaria.postgresql.org; Sat, 01 Dec 2018 14:40:11 +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 1gT6RH-0002S6-6D for pgsql-general@lists.postgresql.org; Sat, 01 Dec 2018 14:40:11 +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 1gT6RA-0007UH-AC for pgsql-general@postgresql.org; Sat, 01 Dec 2018 14:40:10 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 477CB21F23; Sat, 1 Dec 2018 09:40:03 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Sat, 01 Dec 2018 09:40:03 -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=n 2pDP4xqggEKKdXac8CoKRxUgtI9I/Z7zhLBM6kqFOU=; b=5GNosc1at2xuuseIZ txELSTgIE09Eql9xeqgfxHDvypOz/WGIvAuhWfwXAwTOMLZhKs3ju2ZzTO+MzKpi VFZR3ZiD7l6hb6aHUA95XEvePfbIgegawjkgG903eLHwCzG3NIMpc/NqbamjVBk4 oLVuXL/cQ9KYdxkjorW5KayfoRRsdBU0XPmVJT7PY9xMAT/RVWg22yZ03qszZ7oc Z5Ohs7FMXi6M7eh71z3ZsEXpzjgiKegkBE+8QdFJEkJ9CnNcA5WDKrvY8U4SGO95 XDYmcmNiy/+C0K2KcvSrX3dLF8ia/FPOrcdXTxnNf6EVMb6yKatCIqRPA6lXWro0 Nuxbg== 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=n2pDP4xqggEKKdXac8CoKRxUgtI9I/Z7zhLBM6kqF OU=; b=bpd8tnNN3+WohR1LDCRqYMUyOwllYDHOBPbTAYNlt9OaH0xPg6FcKRwYi J/6rOUJpf9vfk2ySZDMz4TwbXvNq5Fe9cutzc/eNLpXdvXCvSEH/3nrtRx8C+lST VvmFE5w36t08zzuWI5S+3IrxWYk4wVU7iHl3hLyGKqw59ZaNmnWeyadmTThpTfE0 d4AEPQx3O1BReHUwirhQnmjHXEkVI3rZ4n0/XhL4qV7RfEcAdhpGG/5aN5vQCKK3 PsXqNKbfEGt2YX5Fgs5mU6okK6nFNUARY7tj/GVVOLnLB8Mm+iABfgOg3Ovkclgt HJSa+uBuP+OZGHvjBhlTKkewL5FJw== 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 40373E4750; Sat, 1 Dec 2018 09:40:02 -0500 (EST) Subject: Re: Process for populating tables in new database To: Rich Shepard , pgsql-general@postgresql.org References: From: Adrian Klaver Message-ID: <3f660180-3ee0-84ef-6668-021d5c8ed347@aklaver.com> Date: Sat, 1 Dec 2018 06:40:01 -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: > > 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. Forgot to add that if you pre-assign the keys to the serial field you will need to advance the sequence to a value past the last key value to avoid a duplicate key error when you let the sequence assign numbers. > > TIA, > > Rich > > > > > > -- Adrian Klaver adrian.klaver@aklaver.com