Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 2FB4316FA501 for ; Mon, 9 Jul 2012 09:25:36 -0300 (ADT) Received: from mahout.postgresql.org ([98.129.198.123]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SoD1x-0004lv-1h for pgsql-bugs@postgresql.org; Mon, 09 Jul 2012 12:25:35 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SoD1j-0005KS-Cp for pgsql-bugs@postgresql.org; Mon, 09 Jul 2012 12:25:20 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1SoD1i-0005T1-Sb for pgsql-bugs@postgresql.org; Mon, 09 Jul 2012 12:25:18 +0000 Date: Mon, 09 Jul 2012 12:25:18 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #6723: Exception for correct query To: pgsql-bugs@postgresql.org From: heiko.helmbrecht@xclinical.com X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201207/67 X-Sequence-Number: 33543 The following bug has been logged on the website: Bug reference: 6723 Logged by: Heiko Helmbrecht Email address: heiko.helmbrecht@xclinical.com PostgreSQL version: 8.4.12 Operating system: Linux Description: = The optimizer is using a where condition for a full table, not to the results of a join/subselect result, that's why it is tried to use casts, that cannot work on the whole table, here are the easy steps to reproduce the problems: create table myTable(id integer, is_current boolean, value varchar(100), ref integer); create table myJoinTable(id integer, name varchar(10)); insert into myTable(id, is_current, value, ref) values = (1,true,'2012-01-15',1), (2,true,'no date',2), (3,false,'2012-01-07',3), (4,false,'2012-01-07',1), (5,false,'2012-01-07',1), (6,false,'2012-01-07',1), (7,false,'2012-01-07',1), (8,false,'2012-01-07',3), (9,true,'2012-01-07',3); insert into myJoinTable(id, name) values (1, 'A'), (2, 'B'), (3, 'A'); select myDate from = (select CAST(t2.value AS DATE) as myDate = from myJoinTable t1 join myTable t2 = on t1.id =3D t2.ref where t2.is_current =3D TRUE and t1.name =3D 'A') myTm= pTable WHERE myDate > '2012-01-01';