Skip site navigation (1) Skip section navigation (2)

Re: ERROR: invalid input syntax for integer: ""

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: kevin burdish <bigswifty00000(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: ERROR: invalid input syntax for integer: ""
Date: 2010-09-23 16:14:42
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
kevin burdish <bigswifty00000(at)gmail(dot)com> writes:
> ERROR:  invalid input syntax for integer: ""
> [from]

>  select l.logid,date_trunc('second',logtime) AS
> date,l.detail,l.status,l.logtype,l.assetid, e.parententityid,e.address
>   from pxlog l -- , pxentity e
> LEFT OUTER JOIN pxentity e ON ( l.assetid::BIGINT ) = e.entityid
> where l.logid >= 99999
> -- AND l.assetid != ''
>         order by l.logid
> limit 10;

Apparently you're trying to cast some empty-string value(s) of l.assetid
to bigint.  Even if the test for that weren't commented out :-(, you
can't really assume that it will be applied before the cast is done.
You could possibly make this work without errors by doing

left join on CASE WHEN l.assetid != '' THEN l.assetid::BIGINT = e.entityid ELSE false END

but don't be surprised if the performance is horrid.

On the whole I'd strongly suggest rethinking your data representation;
the reason this is giving you trouble is you made a bad choice of how
to represent l.assetid.  Perhaps it'd work better if it were a bigint
column in the first place.  It's not clear exactly what you intend the
empty-string entries to mean, but if they mean "unknown" then it'd be
better to use NULL for them.

			regards, tom lane

In response to

pgsql-novice by date

Next:From: Tom LaneDate: 2010-09-23 16:36:47
Subject: Re: User access
Previous:From: kevin burdishDate: 2010-09-23 15:45:27
Subject: ERROR: invalid input syntax for integer: ""

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group