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

From Chris Browne
Subject Re: Alternative to AS?
Date
Msg-id 87sk0jazjp.fsf@cbbrowne.afilias-int.info
Whole thread Raw
In response to Alternative to AS?  (Helgi Örn <sacredeagle@gmail.com>)
Responses Re: Alternative to AS?  (Helgi Örn Helgason <helgi@helgason.nu>)
List pgsql-novice
sacredeagle@gmail.com (Helgi Örn) writes:
> Hi! I am moving a database project from MySQL to PostgreSQL I was a
> newbie there and now I am a newbie here :)
>
> I have this form mysql:
> SELECT tid_in, TIME_FORMAT(tid_in, '%H.%i')AS format FROM timmar;
>
> Which I have gotten postgre to accept thus far:
> SELECT pack_tidin TIME_FORMAT, pack_tidin '%H.%i', AS format FROM timmar;
>
> it stops at AS which doesn't seem to exist is postgre, what is
> postgres alternative to AS?

I see two problems here...

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;

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.
--
(format nil "~S@~S" "cbbrowne" "acm.org")
http://linuxfinances.info/info/postgresql.html
We're Thinking Machines, so we don't have to.

pgsql-novice by date:

Previous
From: Thomas Kellerer
Date:
Subject: Re: Alternative to AS?
Next
From: Thomas Kellerer
Date:
Subject: Re: recurse in a single query