Re: BUG #6673: Value out of range for type integer when adding WHERE clause

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: mfork00(at)yahoo(dot)com
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #6673: Value out of range for type integer when adding WHERE clause
Date: 2012-06-02 17:50:54
Message-ID: 20573.1338659454@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

mfork00(at)yahoo(dot)com writes:
> However, the following query, which is just the above query with 'WHERE
> card.id IS NULL' tacked on to the end fails with an integer out of range.
> Important to know is that parsecardidfromreferencecode will return a valid
> integer ONLY for the rows matching the WHERE clause. However, I cannot see
> how adding the WHERE clause causes that error.

It looks like the planner has chosen to do the joins in a different
order here; the join to activation_event is now done last, so that the
value of the function might be needed for rows it was not needed for
otherwise. This could have occurred in the other version of the query
too; it's all about relative row counts.

Why don't you cast to bigint rather than integer, seeing that the
function is evidently quite capable of returning a bigint value?

If you really must use a join condition involving a function that can
fail for some inputs, possibly the best solution is to mark the function
volatile so that the planner will avoid rearranging stuff that uses it.
This might do some considerable damage to the overall quality of the
plan though.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message shinsetsusan 2012-06-03 09:56:45 BUG #6674: functon aggregat
Previous Message mfork00 2012-06-02 17:34:13 BUG #6673: Value out of range for type integer when adding WHERE clause