Обсуждение: Setting date format for a single output column?

Поиск
Список
Период
Сортировка

Setting date format for a single output column?

От
Michael Schuerig
Дата:
I'd like to get date columns in the results of a query in the
appropriate format (EUROPEAN, GERMAN). I've tried to set DATESTYLE and
it works as far as PgSQL is concerned. Unfortunately, though, this
confuses the date parsing of the O/R-Mapper I'm using[*]. Is there a way
to set the date style/format on a per column basis for the result
returned by a SELECT statement?

Michael


[*] Rails/ActiveRecord. The problem actually lies still deeper in Ruby's
parsedate standard lib method.

--
Michael Schuerig                          Thinking is trying to make up
mailto:michael@schuerig.de                for a gap in one's education.
http://www.schuerig.de/michael/                          --Gilbert Ryle

Re: Setting date format for a single output column?

От
Alvaro Herrera
Дата:
On Wed, Sep 14, 2005 at 02:12:34AM +0200, Michael Schuerig wrote:
>
> I'd like to get date columns in the results of a query in the
> appropriate format (EUROPEAN, GERMAN). I've tried to set DATESTYLE and
> it works as far as PgSQL is concerned. Unfortunately, though, this
> confuses the date parsing of the O/R-Mapper I'm using[*]. Is there a way
> to set the date style/format on a per column basis for the result
> returned by a SELECT statement?

You could SET datestyle just before issuing the query (so it's not a
per-column answer, but per-query), or use the to_char() function instead
of using the default output.

--
Alvaro Herrera -- Valdivia, Chile         Architect, www.EnterpriseDB.com
"Aprende a avergonzarte más ante ti que ante los demás" (Demócrito)

Re: Setting date format for a single output column?

От
Michael Schuerig
Дата:
On Wednesday 14 September 2005 02:32, Alvaro Herrera wrote:
> On Wed, Sep 14, 2005 at 02:12:34AM +0200, Michael Schuerig wrote:
> > I'd like to get date columns in the results of a query in the
> > appropriate format (EUROPEAN, GERMAN). I've tried to set DATESTYLE
> > and it works as far as PgSQL is concerned. Unfortunately, though,
> > this confuses the date parsing of the O/R-Mapper I'm using[*]. Is
> > there a way to set the date style/format on a per column basis for
> > the result returned by a SELECT statement?
>
> You could SET datestyle just before issuing the query (so it's not a
> per-column answer, but per-query), or use the to_char() function
> instead of using the default output.

I had considered that, but I received a better suggestion by private
mail:

  Select to_char(date_column, 'dd/mm/yyyy') as date_column

Thanks to all who responded.

Michael

--
Michael Schuerig                       Face reality and stare it down
mailto:michael@schuerig.de        --Jethro Tull, Silver River Turning
http://www.schuerig.de/michael/