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 1hiRzI-0005y4-UX for pgsql-general@arkaria.postgresql.org; Tue, 02 Jul 2019 23:15:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hiRzH-000678-59 for pgsql-general@arkaria.postgresql.org; Tue, 02 Jul 2019 23:14:59 +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 1hiRzF-000670-V1 for pgsql-general@lists.postgresql.org; Tue, 02 Jul 2019 23:14:58 +0000 Received: from [64.147.123.25] (helo=wout2-smtp.messagingengine.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hiRzC-0006R8-0Z for pgsql-general@lists.postgresql.org; Tue, 02 Jul 2019 23:14:57 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 8049145B; Tue, 2 Jul 2019 19:14:31 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 02 Jul 2019 19:14:31 -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=/ xTfUzR2IiHXCO/iCwc/w5xwMQBgWmZSLRXHR37jg2Q=; b=jaJbN29GFLgycZAkK mBHe7RKwmsinUTxR724uu0JrbKx63ghGNGWRZ0n/nqaqe2MTn0d7QJjru35R+5re zpHsONThXawXqoHWASTbTIKV3M+1lTJ1bte2+SNHvU1yLC+Qj6o4IzNFNYJjVRIp 7U9pl7SAly3vdjds7Qdvr08dB4O/3f8UBeahMaBIlHXp8W10PVmj0Vv8zPdimyUh +6fqcX4o/QqVhBHwhFxfDmwlKnAaTnChakNf/UK9G96zolIZ2anGzsO9x+JWAyoc vcPJy77CCc3wrApTYA2hDEqt/cJiLC2uQ9D/eo9h9Rk6d3AH+XcBZ2GS6t1HvkZq MgNhQ== 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=/xTfUzR2IiHXCO/iCwc/w5xwMQBgWmZSLRXHR37jg 2Q=; b=vt1mTgYQ1znlPDy+wAfsy4vmEIPj4JzLlYWgvXRCvksbGymyCFBXG9uJX ZoAnP5lRLJY057lcTKz7t/e1qDwEeCNW6K4qcxivICtCwaZGSs5ZMB9Bsb8SHfuy 2rcyHBnYMHSLDb8/ybrvJlnueZ0fA94ERetXfRIxFTGRFAG3xDVjvLjuqRDz4pAZ k5kc2gvP4J7aiomVRzl3abDCZngRtNKKZW+HMxTlDNHjIYY2qIplGsIWqW2tMcPr z/vglo4ZdurHgtUF5bWmeMvP++PPOWOEDfdW1ETcpH3aPiTwN2jgfAgziyyxgNIC /H5xGJ1HrEyi368oMbUSppXWZcGig== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrvdelgddukecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefuvfhfhffkffgfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughrihgr nhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh eqnecuffhomhgrihhnpeifihhkihhpvgguihgrrdhorhhgpdhpohhsthhgrhgvshhqlhdr ohhrghdptgihsggvrhhtvggtqdhpohhsthhgrhgvshhqlhdrtghomhenucfkphephedtrd duleejrdektddrvdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgr vhgvrhesrghklhgrvhgvrhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from ranger.suse (50-197-80-2-static.hfc.comcastbusiness.net [50.197.80.2]) by mail.messagingengine.com (Postfix) with ESMTPA id 08145380085; Tue, 2 Jul 2019 19:14:29 -0400 (EDT) Subject: Re: To: Andrew Kerber , raf@raf.org Cc: pgsql-general@lists.postgresql.org References: <45312c734ff4177639b309940be4017d91f4a38b.camel@cybertec.at> <20190702230427.sgmhd6wwf2j5mima@raf.org> From: Adrian Klaver Message-ID: <1c5d14ca-c519-bcb3-a912-9d1d77022c73@aklaver.com> Date: Tue, 2 Jul 2019 16:14:28 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 64.147.123.25 (deferred) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 7/2/19 4:08 PM, Andrew Kerber wrote: > Yes, CSV stands for comma separated variable length.  This means that CSV = Comma Separated Values > the fields in each row should be separated by commas, with a carriage > return at the end of each record.  You have a file using | separators, > which mean it is not csv. That is not strictly true: https://en.wikipedia.org/wiki/Comma-separated_values And is definitely not true for this context, using Postgres COPY: https://www.postgresql.org/docs/9.6/sql-copy.html "CSV Format This format option is used for importing and exporting the Comma Separated Value (CSV) file format used by many other programs, such as spreadsheets. Instead of the escaping rules used by PostgreSQL's standard text format, it produces and recognizes the common CSV escaping mechanism. The values in each record are separated by the DELIMITER character. If the value contains the delimiter character, the QUOTE character, the NULL string, a carriage return, or line feed character, then the whole value is prefixed and suffixed by the QUOTE character, and any occurrence within the value of a QUOTE character or the ESCAPE character is preceded by the escape character. You can also use FORCE_QUOTE to force quotes when outputting non-NULL values in specific columns. ... " You do have to specify the delimiter if it is not the default comma. In the OP's case the delimiter would need to be set to '|'. > > On Tue, Jul 2, 2019 at 6:04 PM > wrote: > > Laurenz Albe wrote: > > > On Tue, 2019-07-02 at 13:09 +0530, Prakash Ramakrishnan wrote: > > > We are getting below error while during import the csv file > please do the needful. > > > > I'd say the needful thing here is for you to read the > documentation... > > > > > -bash-4.2$ more ckr_sto.csv > > >  4937880 |     12 | 2015-01-05  |            | 2015-01-05 > 05:51:47 |         |        | 5000128790679 |           | >  |           | > > >  4939355 |     12 | 2015-01-05  |            | 2015-01-05 > 05:51:47 |         |        | 5000128639345 |           | >  |           | > > >  4939744 |     12 | 2015-01-05  |            | 2015-01-05 > 05:51:47 |         |        | 5000128684510 |           | >  |           | > > >  4939750 |     12 | 2015-01-05  |            | 2015-01-05 > 05:51:47 |         |        | 5000128683100 |           | >  |           | > > >  4936360 |     12 | 2015-01-05  |            | 2015-01-05 > 05:51:47 |         |        | 5000128567527 |           | >  |           | > > >  4940308 |     12 | 2015-01-05  |            | 2015-01-05 > 05:51:47 |         |        | 5000128781329 |           | >  |           | > > >  4938006 |     12 | 2015-01-05  |            | 2015-01-05 > 05:51:47 |         |        | 4000128912554 |           | >  |           | > > >  4937457 |     12 | 2015-01-05  |            | 2015-01-05 > 05:51:47 |         |        | 5000128426574 |           | >  |           | > > > > > > error > > > ---------- > > > postgres=# \copy ckr_sto from /data/ckr_sto.csv CSV HEADER; > > > ERROR:  invalid input syntax for integer: " 4939355 |     12 | > 2015-01-05  |            | 2015-01-05 05:51:47 |         |        | > 5000128639345 |           |           |           | " > > > CONTEXT:  COPY ckr_sto, line 2, column pod_id: " 4939355 | >  12 | 2015-01-05  |            | 2015-01-05 05:51:47 |         | >     | 500012863934..." > > > > >From the documentation of COPY: > > > > DELIMITER > > > >     Specifies the character that separates columns within each > row (line) of the file. > >     The default is a tab character in text format, a comma in CSV > format. > >     This must be a single one-byte character. This option is not > allowed when using binary format. > > > > Yours, > > Laurenz Albe > > -- > > Cybertec | https://www.cybertec-postgresql.com > > in other words, ckr_sto.csv is not a csv file. > it just has .csv at the end of its name. > that's why psql tried to interpret the entire > line as the first column: there were no commas. > > its contents should look something like: > > 4937880,12,2015-01-05,,2015-01-05 05:51:47,,,5000128790679,,,, > 4939355,12,2015-01-05,,2015-01-05 05:51:47,,,5000128639345,,,, > 4939744,12,2015-01-05,,2015-01-05 05:51:47,,,5000128684510,,,, > 4939750,12,2015-01-05,,2015-01-05 05:51:47,,,5000128683100,,,, > 4936360,12,2015-01-05,,2015-01-05 05:51:47,,,5000128567527,,,, > 4940308,12,2015-01-05,,2015-01-05 05:51:47,,,5000128781329,,,, > 4938006,12,2015-01-05,,2015-01-05 05:51:47,,,4000128912554,,,, > 4937457,12,2015-01-05,,2015-01-05 05:51:47,,,5000128426574,,,, > > > > > > -- > Andrew W. Kerber > > 'If at first you dont succeed, dont take up skydiving.' -- Adrian Klaver adrian.klaver@aklaver.com