select my_function( timeofmeasurement, longitude ) as solarnoon, extract(epoch from ( timeofmeasurement - solarnoon ) as solardiff ( case when solardiff < 3600 then 'Y' else 'N' end ) as within_solar_hour from my_table; But I get an error along the lines of ERROR: column "solarnoon" does not exist LINE 8: extract(epoch from (timeofmeasurement - solarnoon) ) as sola... It's probably a compile-time run-time sort of chicken and egg thing. ;) >>>>>>>>>>>>>>>>>>>>>>>>> It is. You need to use sub-selects. SELECT solarnoon, solardiff, CASE... AS within_solar_hour FROM SELECT solarnoon, func() AS solardiff FROM ( SELECT func() AS solarnoon ) AS sn -- close solarnoon from ) AS sd -- close solardiff from David J. -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general