Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jlx5c-0004cR-OO for pgsql-admin@arkaria.postgresql.org; Thu, 18 Jun 2020 16:08:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jlx5b-0002PU-Ms for pgsql-admin@arkaria.postgresql.org; Thu, 18 Jun 2020 16:08:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jlx5a-0002PJ-JK; Thu, 18 Jun 2020 16:08:31 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jlx5W-0000hT-VC; Thu, 18 Jun 2020 16:08:30 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 3916D5C00E0; Thu, 18 Jun 2020 12:08:25 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 18 Jun 2020 12:08:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=k tJcH2L8RLRGQmzKYKUtdEiv2mkksa3Ii9Q1jq1cyC8=; b=kuH5+SEqrUjE8qQjL jIwKGXN4zxPocTBSBaCsLl2DcT5F84fnD9a1cE1S5dFGGw6LKeSDgLFYY7JNlGXT tOC/za96xUcs2cW5aubz3urKjQFhIwE0wW5GemUOP7iIb7ibG05HSaYaZt79U/mu FlZJjH8ahYPtOm2GuzR7zGpaUI2+9FOdy2m/TQ+fqvQeGbvn3aYc9hSgw/XaXiDs 0HXoBfGqTBz6ch2cB+Bub9eibGQaU/EqxeKiwyufyjuKd4gaPvaOnv4jBLjE2jF8 JahQHaxhHMy8i5Ph2aJHhP6HtAZTtMBK0KzcKubiRs8okm13z34rPB6l2NKsEki4 KDrSw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=fm3; bh=ktJcH2L8RLRGQmzKYKUtdEiv2mkksa3Ii9Q1jq1cy C8=; b=UzhgnXv9ZRqjsUBHJCcekkkIokHEyJAezKbRinSgxVYWB/hCM3ccUsQ9c u6OnIsbTXmhubks5hpBubDhA1mFtcSAVZkqUE+v9ZbG1av88Ugr7KDdkaxKu+XyJ rhd1FKau6nDIU5TNbe6mfT19RlAErq/vCe2D8A2eg3l99wdwqhhdB3cz7Sh+qSK2 8aqXwm3JRDnkUdKi1YhWSsgQEs+mvDvRna+IMGPUX77k7eriA4rQUl6FKGZ0UV65 0pwsHJaxtWOfTDyeMXlrx06NVL7xZ48SsemWEKDbWxr3yz3dUW8tEp6UFAoP40uU qAjFNy/0sB93KSrp6hlUfqW7/Cn5w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrudejgedgleekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeegteevfeeugfeltdfgtdduieehhfefvdfgiedvudfh ieeuteejueeghfeuhefgveenucffohhmrghinhepfihikhhiphgvughirgdrohhrghenuc fkphepjeehrddujedvrdehrddvfedunecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtg homh X-ME-Proxy: Received: from [192.168.1.3] (75-172-5-231.tukw.qwest.net [75.172.5.231]) by mail.messagingengine.com (Postfix) with ESMTPA id 4426E3061DC5; Thu, 18 Jun 2020 12:08:24 -0400 (EDT) Subject: Re: create batch script to import into postgres tables To: Pepe TD Vo , Christopher Browne Cc: Pgsql-admin , Pgsql-general References: <866581879.1147164.1592317256828.ref@mail.yahoo.com> <866581879.1147164.1592317256828@mail.yahoo.com> <1f5f4fd6-ad22-4823-c922-17a021c2c0d7@aklaver.com> <74046808.1129536.1592317823808@mail.yahoo.com> <3625e291-8456-3831-6205-2d73232bcd1e@aklaver.com> <1718146430.1151531.1592319564343@mail.yahoo.com> <1761277119.1163490.1592322138731@mail.yahoo.com> <732982585.145357.1592493607620@mail.yahoo.com> From: Adrian Klaver Message-ID: Date: Thu, 18 Jun 2020 09:08:23 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <732982585.145357.1592493607620@mail.yahoo.com> 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 6/18/20 8:20 AM, Pepe TD Vo wrote: Please don't top post. The preferred style on this list is inline or bottom posting(https://en.wikipedia.org/wiki/Posting_style). > I have a Postgresql client installed and connected.  how can i create a > batch script running from the client window? Create a file with commands in it like the example from Christopher Browne that was posted earlier: "There is no single straightforward answer to that. Supposing I want a batch to either all be processed, or to all not process, then I might write a sql file like: begin; \copy table_1 (c1, c2, c3) from '/path/tabledata1.csv' csv header; \copy table_2 (c1, c2, c3) from '/path/tabledata2.csv' csv header; \copy table_3 (c1, c2, c3) from '/path/tabledata3.csv' csv header; commit; But you may be fine with having a separate SQL script for each table. There will be conditions where one or the other is more appropriate, and that will be based on the requirements of the process." Then point psql at it: psql -d some_db -h some_host -U some_user -f the_file Be aware that \copy is all or nothing. If there is a single failure in the copying the whole copy will rollback. Given that the one file per table might be preferable. > > ** > *Bach-Nga > -- Adrian Klaver adrian.klaver@aklaver.com