From: Tom Lane <tgl@sss.pgh.pa.us>
To: mfork00@yahoo.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #6673: Value out of range for type integer when adding WHERE clause
Date: Sat, 02 Jun 2012 13:50:54 -0400
Message-ID: <20573.1338659454@sss.pgh.pa.us> (raw)
In-Reply-To: <E1SasDN-0002gu-33@wrigleys.postgresql.org>
References: <E1SasDN-0002gu-33@wrigleys.postgresql.org>
mfork00@yahoo.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
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-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, mfork00@yahoo.com
Subject: Re: BUG #6673: Value out of range for type integer when adding WHERE clause
In-Reply-To: <20573.1338659454@sss.pgh.pa.us>
References: <E1SasDN-0002gu-33@wrigleys.postgresql.org> <20573.1338659454@sss.pgh.pa.us>
* 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