Re: subtract a day from the NOW function - Mailing list pgsql-sql

From Michael Glaesemann
Subject Re: subtract a day from the NOW function
Date
Msg-id 7719EE57-A3BA-4301-9C94-B4FD5DBA3FCB@seespotcode.net
Whole thread Raw
In response to Re: subtract a day from the NOW function  ("Fernando Hevia" <fhevia@ip-tel.com.ar>)
List pgsql-sql
On Jun 7, 2007, at 15:38 , Fernando Hevia wrote:

> Why not? I'm curious if has anything to do with performance or just
> style?

Not style. Maybe performance because there's fewer function calls,
but primarily correctness. By using to_char you no longer have a date—
you have a text value—and are relying on the collocation of your
database to compare two text values. This can lead to subtle bugs in
your code. Similarly, I would never use to_char to compare two integers:

SELECT 20 > 9 AS int_values    , to_char(20, '9') > to_char(9, '9') AS text_values;

Is this what you would expect? What's the advantage to using to_char?

Michael Glaesemann
grzm seespotcode net




pgsql-sql by date:

Previous
From: Osvaldo Kussama
Date:
Subject: Re: subtract a day from the NOW function
Next
From: Michael Glaesemann
Date:
Subject: Re: subtract a day from the NOW function