pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jeff Boes <jboes@qtm.net>
To: pgsql-sql@postgresql.org
Subject: Formatting problems with negative intervals, TO_CHAR
Date: Thu, 03 Jun 2004 20:03:17 GMT
Message-ID: <13d849b7ee63de04179c102cb25159d2@news.teranews.com> (raw)

This seems ... well, counter-intuitive at least:

(using Pg 7.4.1)

# select to_char('4 minutes'::interval -
'5 minutes 30 seconds'::interval, 'mi:ss');

  to_char
---------
  -1:-3
(1 row)

Why is the trailing zero lost? Why are there two minus signs?

I would expect '-1:30'.

Likewise,

# select to_char('4 minutes'::interval -
'4 minutes 30 seconds'::interval,
# 'mi:ss');

  to_char
---------
  00:-3
(1 row)


I would expect '-00:30'.

I ended up fixing this with a very convoluted expression:

... case when last.time_count > prev.time_count then '+' else '-' end ||
     to_char((abs(extract(epoch from last.time_count) -
     extract(epoch from prev.time_count)) ||
     'seconds')::interval,'FMmi:ss.cc')


but I have to believe there is an easier way.

-- 
(Posted from an account used as a SPAM dump. If you really want to get
in touch with me, dump the 'jboes' and substitute 'mur'.)
________
Jeffery Boes <>< jboes@qtm.net



view thread (5+ messages)  latest in thread

Message-ID: <13d849b7ee63de04179c102cb25159d2@news.teranews.com>
Permalink:  ../13d849b7ee63de04179c102cb25159d2@news.teranews.com/
Also on:    postgresql.org/message-id/13d849b7ee63de04179c102cb25159d2@news.teranews.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: jboes@qtm.net
  Subject: Re: Formatting problems with negative intervals, TO_CHAR
  In-Reply-To: <13d849b7ee63de04179c102cb25159d2@news.teranews.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox