From: | Craig Ringer <craig(at)postnewspapers(dot)com(dot)au> |
---|---|
To: | "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: How to get DATE in server locale format |
Date: | 2010-01-11 23:18:58 |
Message-ID: | 4B4BB1E2.5000109@postnewspapers.com.au |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Craig Ringer | 2010-01-11 23:25:44 | Re: Using a lock to avoid: could not open relation with OID |
Previous Message | Omar Mehmood | 2010-01-11 23:02:18 | replication from multiple "master" servers to a single read-only slave |