On 11/01/2010 9:44 PM, A. Kretschmer wrote:
In response to Andrus :
How to get localized date for single conversion inside SELECT statement so
that it works in different server lc_time settings ?
As Tom said, you can use to_char():
It looks like the OP wants a localized date, just one different to that
specified by the datestyle GUC, for just one date-to-string conversion
within a function that may have others.
Essentially, I think they're after
SET datestyle = DMY;
SELECT date_with_style(somedate, 'MDY'), somedate::text;
... which doesn't exist.
Andrus: Is the date style you need for the one "different" call fixed?
Or does it vary?
If it's fixed, you *can* just use to_char with a constant format string.
If the format needed for the "different" call varies, you'll have to
either have your app send a suitable to_char format string, or you'll
need to write a function that accepts a Pg datestyle parameter and
internally calls to_char with the appropriate format depending on the
value of the passed datestyle.
There's no way to say:
-- This does not work
SELECT CAST(somedate AS text WITH DATESTYLE 'iso')
or the like.
--
Craig Ringer
--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general