| From: | Michael Glaesemann <grzm(at)seespotcode(dot)net> |
|---|---|
| To: | "Fernando Hevia" <fhevia(at)ip-tel(dot)com(dot)ar> |
| Cc: | <pgsql-sql(at)postgresql(dot)org> |
| Subject: | Re: subtract a day from the NOW function |
| Date: | 2007-06-07 21:53:03 |
| Message-ID: | 7719EE57-A3BA-4301-9C94-B4FD5DBA3FCB@seespotcode.net |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | George Pavlov | 2007-06-07 21:56:06 | Re: index vs. seq scan choice? |
| Previous Message | Osvaldo Kussama | 2007-06-07 21:41:21 | Re: subtract a day from the NOW function |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Michael Glaesemann | 2007-06-07 21:58:03 | Re: subtract a day from the NOW function |
| Previous Message | Osvaldo Kussama | 2007-06-07 21:41:21 | Re: subtract a day from the NOW function |