Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YkZdv-00013H-AK for pgsql-sql@arkaria.postgresql.org; Tue, 21 Apr 2015 14:59:19 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YkZdu-00028C-Gj for pgsql-sql@arkaria.postgresql.org; Tue, 21 Apr 2015 14:59:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YkZds-00025o-Om for pgsql-sql@postgresql.org; Tue, 21 Apr 2015 14:59:16 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YkZdo-0002mB-3x for pgsql-sql@postgresql.org; Tue, 21 Apr 2015 14:59:15 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 078232069E for ; Tue, 21 Apr 2015 10:59:10 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Tue, 21 Apr 2015 10:59:10 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=Hzdwh/7WRa0/+mejAqgsb5BpcIs=; b=S3uSNn nS8hVHlGi44zIFBZaKKwP0UbiLBJ97NQooe7q1ZqLEEx/HuUBBLXNWjvaRzIy7PN nSCXQ63glfgKATjiCRjzUQ0aovOOAoc+pTwfknLHjN0I+wUAfqTjBKDonPcdtqRg Pf3rYsBiYt5J+1dS8ZNqNKP2tr8OEYj3hPogQ= DKIM-Signature: v=1; a=rsa-sha1; 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-sasl-enc:x-sasl-enc; s=smtpout; bh=Hzdwh/7WRa0/+me jAqgsb5BpcIs=; b=Pvz1p++cZNmxDDlqw7VjYii82uZ+Ay9lGwiHpiVqNBw61lS KbJyj0eJndojWrXsqynLPNaKCfnlls+O4cESlu3RLrAfZjxjF6w2H/rotSOT2XMA DgUd77WhsZVUWJp8FCZkOYBCDQtjlR/wZcN8eH6HNxEev81BpYOlezCp9go8= X-Sasl-enc: sGJZFNDmLM8OdIHvPyy7tDjPQ9Wd1TaRZDrS2GptcwzE 1429628349 Received: from [192.168.1.2] (unknown [174.21.218.98]) by mail.messagingengine.com (Postfix) with ESMTPA id 7EEE46801A1; Tue, 21 Apr 2015 10:59:09 -0400 (EDT) Message-ID: <553665BC.7030400@aklaver.com> Date: Tue, 21 Apr 2015 07:59:08 -0700 From: Adrian Klaver User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Shawn Gennaria , pgsql-sql@postgresql.org Subject: Re: How to determine offending column for insert exceptions References: In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org On 04/21/2015 07:39 AM, Shawn Gennaria wrote: > Hi all, > > I'm attempting to parse a data set of very many columns from numerous > CSVs into postgres so I can work with them more easily. To this end, > I've created some dynamic queries for table creation, copying from CSVs > into a temp table, and then inserting the data to a final table with > appropriate data types assigned to each field. The majority of the data > can fit into integer fields, but occasionally I hit some entries that > need to be text or bigint or floats. Therefore my dynamic queries fail > with 'integer out of range' errors and such. Unfortunately, sometimes > this happens on a file with thousands of columns, and I'd like to easily > figure out which column the erroneous input belongs to without having to > manually scour through it. At this point, the data has already been > copied into a temp table, so the query producing these errors looks like: > > INSERT INTO final_table > SELECT a::int, b::int FROM temp_table > > temp_table contains all text fields (since COPY points there and I'd > rather not debug at that stage), so I'm trying to coerce them to more > appropriate data types with this insert statement. > > From this, I'd get an error with SQLSTATE like 22003 and SQLERRM like > 'value "2156947514" is out of range for type integer'. I'd like to be > able to handle the exception gracefully and modify the data type of the > appropriate column, but I don't know how to determine which column > contains this data. Not sure, but some more information might help: 1) What Postgres version? 2) You mention you are doing this dynamically. Where is that happening? In a stored function? If so what language? In an external program? 3) How are you handling the exception now? > > I hope this is possible. > > Thanks! > sg -- Adrian Klaver adrian.klaver@aklaver.com -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql