Re: Alternative to AS?

From: Helgi Örn Helgason <helgi(at)helgason(dot)nu>
To: PostgreSQL - newbie <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Alternative to AS?
Date: 2010-10-06 20:20:44
Message-ID: AANLkTimNBFzRS2O3bkGbsHoMZN1UK8zfZctDEtj9VXn2@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

> 1.  You need to use Postgres idioms for the reformatting of the date.
>
>  <http://www.postgresql.org/docs/9.0/static/functions-formatting.html>
>
> 2.  You put in a syntax error when you put in an extra comma.
>
> Instead of:
>> SELECT pack_tidin TIME_FORMAT, pack_tidin '%H.%i', AS format FROM timmar;
>                                                   ^
> Take out the comma to get:
>  SELECT pack_tidin TIME_FORMAT, pack_tidin '%H.%i' AS format FROM timmar;
>
> Possibly a more suitable query would be:
>
>  select pack_tidin, to_char (pack_tidin, 'HH.MI') as format from timmar;
>
This works fine, the only problem is the outcome the two columns:

pack_tidin | format
------------+--------
07:45:00 | 07.45
08:00:00 | 08.00
07:00:00 | 07.00
06:30:00 | 06.30

This is precisely what I wanted:

ekobas=# SELECT to_char(pack_tidin, 'HH24.MI') AS format FROM timmar;
format
--------
07.45
08.00
07.00
06.30

> I'm assuming that '%H.%i' is intended to return hours and minutes,
> separated by a ".".  You can probably get more useful guidance from the
> URL listed above.
>
Yes, the time format in the database is hh:mm:ss which I do not want
om my page, I want this hh.mm which is quite common in at least in
europe.

Thank's,
/HÖ

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Thomas Kellerer 2010-10-06 20:25:02 Re: Alternative to AS?
Previous Message Jean-Yves F. Barbier 2010-10-06 20:17:50 Re: recurse in a single query