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

Re: Interval output format

From: "Stefan Waidele jun(dot)" <St(dot)Waidele(dot)jun(at)Krone-Neuenburg(dot)de>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Interval output format
Date: 2001-01-18 21:40:22
Message-ID: 5.0.2.1.0.20010118221111.00aad0b0@imap.Krone-Neuenburg.de (view raw or flat)
Thread:
Lists: pgsql-novice
At 13:37 18.01.2001 -0500, Tom Lane wrote:
>"Stefan Waidele jun." <St(dot)Waidele(dot)jun(at)Krone-Neuenburg(dot)de> writes:
> > How can I tell Postgres to return an interval value in an format like 
> hhh:mm?
>
>See to_char(),
>http://www.postgresql.org/devel-corner/docs/postgres/functions-formatting.htm
>
>                         regards, tom lane

Thanks Tom,

I have been at this page before and did not get a clue.
Have I overlooked something? (Note: I am using an interval, not a date)
It would be great to have an example, since to_char('1 14:30', 'hh:mm') 
(and others) gave me errors.

On the next page I have found dat_part(), and solved my problem using:
select date_part('day', sum(gearbeitet))*24+date_part('hour', 
sum(gearbeitet))||':'||date_part('min', sum(gearbeitet)) from stunden;

But here comes the next problem:
When I tried to do a SQL-Function

create function sum_gearbeitet(text)
returns text
as "select 
date_part('day',sum(gearbeitet))*24+date_part('hour',sum(gearbeitet))||':'||date_part('min',sum(gearbeitet)) 
from stunden;"
language 'sql';

  psql said:

NOTICE:  identifier "select 
date_part('day',sum(gearbeitet))*24+date_part('hour',sum(gearbeitet))||':'||date_part('min',sum(gearbeitet)) 
from stunden;" will be truncated to "select date_part('day',sum(gear"
ERROR:  parser: parse error at or near """

What am I doing wrong? (shorter functions are also truncated)

Stefan


In response to

Responses

pgsql-novice by date

Next:From: Laurel WilliamsDate: 2001-01-18 22:30:18
Subject: Postgres superuser password issue--update
Previous:From: Tom LaneDate: 2001-01-18 21:15:18
Subject: Re: ERROR: plpgsql: cache lookup from pg_proc failed -- Why?

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