Skip site navigation (1) Skip section navigation (2)

Re: Alternative to AS?

From: Chris Browne <cbbrowne(at)acm(dot)org>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Alternative to AS?
Date: 2010-10-06 19:31:22
Message-ID: 87sk0jazjp.fsf@cbbrowne.afilias-int.info (view raw or flat)
Thread:
Lists: pgsql-novice
sacredeagle(at)gmail(dot)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(at)~S" "cbbrowne" "acm.org")
http://linuxfinances.info/info/postgresql.html
We're Thinking Machines, so we don't have to.

In response to

Responses

pgsql-novice by date

Next:From: Thomas KellererDate: 2010-10-06 19:42:12
Subject: Re: recurse in a single query
Previous:From: Jean-Yves F. BarbierDate: 2010-10-06 19:25:44
Subject: recurse in a single query

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group