pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: tango ward <tangoward15@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: psycopg2.DataError: invalid input syntax for integer: ""
Date: Mon, 7 May 2018 06:49:38 -0700
Message-ID: <e40dbb5a-199f-887b-15b6-9a94f031a813@aklaver.com> (raw)
In-Reply-To: <CAA6wQLLWBRZvnLYLHxhiV9LLfDPDFxCkt1wUZmw4-ZOwSC0nNw@mail.gmail.com>
References: <CAA6wQLJjNYtnXwQR14TtSK2eEAVmxy-zc-Uy1zqQYOF56VqxvQ@mail.gmail.com>
	<CAKFQuwafnE4hCacPP25kcAH6dRzuf7kBdBDd8JJptDBC8PqdLQ@mail.gmail.com>
	<CAA6wQLJF-TYuE5b1gLVaCjmeo+KyL26FwwD_pwNE54CBkkjwEA@mail.gmail.com>
	<CAKFQuwaZX4zLDU0pKr+Hk2H6UDndtVd2XULNvz6o=HPu+f1v3Q@mail.gmail.com>
	<CAA6wQL+mxtYNf6-jYWpqT=WZMEy4ePL1bH+BbYmcO+1FBqdOTA@mail.gmail.com>
	<CAKFQuwZhP9-z7psieZFMbkAFNLzsbjShUBKvF-8ikeQ_JtiSfw@mail.gmail.com>
	<CAA6wQLLi=Q53=i3N5b1QQSm3EgpDH0o9d_-fhmgCt3EXKwAf9g@mail.gmail.com>
	<CAKFQuwb9UDfsn3CzgR+Fb7Hpbt8aLiJOdWK45C65Gj2GCD9Mtg@mail.gmail.com>
	<CAA6wQLLWBRZvnLYLHxhiV9LLfDPDFxCkt1wUZmw4-ZOwSC0nNw@mail.gmail.com>

On 05/07/2018 12:28 AM, tango ward wrote:
> I think I've found the culprit of the problem.
> 
> I have a field which is varchar from the source DB while on the 
> destination DB its integer.
> 
> Reading the documentation: 
> http://www.postgresqltutorial.com/postgresql-cast/ but it gives me error 
> `psycopg2.DataError: invalid input syntax for integer: ""`

Would need to see your code to be sure, but I am gong to guess you are 
trying to CAST the string to integer in the SQL e.g CAST(some_str_value 
AS INTEGER) or some_str_value::integer. The error you are getting is :

test=# select CAST('' AS INTEGER);
ERROR:  invalid input syntax for integer: ""
LINE 1: select CAST('' AS INTEGER);
                     ^
test=# select ''::integer;
ERROR:  invalid input syntax for integer: ""
LINE 1: select ''::integer;

Two options:

1) You will need the catch the '' on the Python side before they get to 
the database and turn them into None(if Nulls allowed in column) or 0 
otherwise.

2) If possible convert the integer column on the destination db to a 
varchar one. Though I would do some investigation before doing this as 
this may very well mess up other code.

> 
> On Mon, May 7, 2018 at 2:39 PM, David G. Johnston 
> <david.g.johnston@gmail.com <mailto:david.g.johnston@gmail.com>> wrote:
> 
>     On Sunday, May 6, 2018, tango ward <tangoward15@gmail.com
>     <mailto:tangoward15@gmail.com>> wrote:
> 
>         Yes, my apologies.
> 
>         May I also ask if there's a limitation for the number of
>         timestamp with timezone fields in a table?
> 
> 
>     Not one that is likely to matter in practice.  There's a page
>     discussing limitations on the website/docs somewhere if you wish to
>     find out more.
> 
>     David J.
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com




view thread (10+ messages)  latest in thread

Message-ID: <e40dbb5a-199f-887b-15b6-9a94f031a813@aklaver.com>
Permalink:  ../e40dbb5a-199f-887b-15b6-9a94f031a813@aklaver.com/
Also on:    postgresql.org/message-id/e40dbb5a-199f-887b-15b6-9a94f031a813@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, tangoward15@gmail.com
  Subject: Re: psycopg2.DataError: invalid input syntax for integer: ""
  In-Reply-To: <e40dbb5a-199f-887b-15b6-9a94f031a813@aklaver.com>
  References: <CAA6wQLJjNYtnXwQR14TtSK2eEAVmxy-zc-Uy1zqQYOF56VqxvQ@mail.gmail.com> <CAKFQuwafnE4hCacPP25kcAH6dRzuf7kBdBDd8JJptDBC8PqdLQ@mail.gmail.com> <CAA6wQLJF-TYuE5b1gLVaCjmeo+KyL26FwwD_pwNE54CBkkjwEA@mail.gmail.com> <CAKFQuwaZX4zLDU0pKr+Hk2H6UDndtVd2XULNvz6o=HPu+f1v3Q@mail.gmail.com> <CAA6wQL+mxtYNf6-jYWpqT=WZMEy4ePL1bH+BbYmcO+1FBqdOTA@mail.gmail.com> <CAKFQuwZhP9-z7psieZFMbkAFNLzsbjShUBKvF-8ikeQ_JtiSfw@mail.gmail.com> <CAA6wQLLi=Q53=i3N5b1QQSm3EgpDH0o9d_-fhmgCt3EXKwAf9g@mail.gmail.com> <CAKFQuwb9UDfsn3CzgR+Fb7Hpbt8aLiJOdWK45C65Gj2GCD9Mtg@mail.gmail.com> <CAA6wQLLWBRZvnLYLHxhiV9LLfDPDFxCkt1wUZmw4-ZOwSC0nNw@mail.gmail.com> <e40dbb5a-199f-887b-15b6-9a94f031a813@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox