Thursday, April 24, 2008

sql code readability

though logically the same, this is easier to read:

select coalesce(
(select CURRENT_TIMESTAMP > unlocked_expiration
from invoice
where invoice_rec_id = 'value here'), true) as has_expired


than this:

select coalesce(
(select unlocked_expiration < CURRENT_TIMESTAMP
from invoice
where invoice_rec_id = 'value here'), true) as has_expired