consider below query
select ...
(
select ... from
(
select * from trips where deviceid=ANY('{22}'::int[]) order by startts
) as sortedtrips group by deviceid
) as V
right join devices D on D.deviceid=V.deviceid
left join mostrecent M on M.deviceid=D.deviceid
left join v_auto_odometer DD on DD.deviceid=M.deviceid
where D.deviceid=ANY('{22}'::int[])
It used to run fine in both my production as staging environment. Suddenly this query no longer runs in staging, but does run in production.
The culprit seems to be the last "where" clause
... where D.deviceid=ANY('{22}'::int[])
which results into
ERROR: invalid input syntax for integer: ""
********** Error **********
ERROR: invalid input syntax for integer: ""
SQL state: 22P02
Changing this to
D.deviceid=22
resolves the issue (but note that a very similar where clause is still available in the query and does not give problems).
I have absolutely no idea what happened, and why the query is no longer working. it seems related to the specific postgres environment, which differ in the subversion
staging:PostgreSQL 9.3.5
production:PostgreSQL 9.3.4
I really need to use the ANY statement (as the above query is a mere example. The real query uses an actual array of id's.
Can anyone help?
Thanks all for your comments.
In the end, the problem was related to a data mismatch between staging and prodution. A null value in a specific column caused the issue in staging.
Postgres was not helping me with the specific error messages.