On 08/10/2013 21:50, Brian Wong wrote:
Unless I'm much mistaken, there is no guarantee that the conditions in a WHERE clause will be checked in any particular order, because SQL does not specify a procedural recipe, only a logical one. If for whatever reason the query planner decides to check the condition involving to_date first, it will have to evaluate it for all rows in the table, leading to this error. It works fine in the SELECT clause because that happens logically after all filtering has taken place. I'm not sure if there are easier ways, but one way to force the order would be to restrict the set of tables in a sub-query or CTE first, and then check whatever you need about the date: With tables_with_dates As ( select table_name, to_date(right(table_name, 8), 'YYYYMMDD') blah from information_schema.tables where table_schema = '????' and table_catalog = '????' ) Select table_name, blah Where blah > '2013-01-01'::date -- Rowan Collins [IMSoP] |