Re: Alternative to AS? - Mailing list pgsql-novice

From Helgi Örn Helgason
Subject Re: Alternative to AS?
Date
Msg-id AANLkTimNBFzRS2O3bkGbsHoMZN1UK8zfZctDEtj9VXn2@mail.gmail.com
Whole thread Raw
In response to Re: Alternative to AS?  (Chris Browne <cbbrowne@acm.org>)
List 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Ö

pgsql-novice by date:

Previous
From: "Jean-Yves F. Barbier"
Date:
Subject: Re: recurse in a single query
Next
From: Thomas Kellerer
Date:
Subject: Re: Alternative to AS?