pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mischa Sandberg <mischa.sandberg@telus.net>
To: pgsql-sql@postgresql.org
Subject: Re: SQL output
Date: Mon, 15 Aug 2005 17:26:34 -0700
Message-ID: <1124151994.430132baa4e4e@webmail.telus.net> (raw)
In-Reply-To: <84C5C116-630B-4363-AF37-FF38F9BBC813@gmail.com>
References: <84C5C116-630B-4363-AF37-FF38F9BBC813@gmail.com>

Quoting Simon Law <simonslaw@gmail.com>:

> 
> CREATE TABLE tablename (field INTERVAL);
> INSERT INTO tablename VALUES('3 weeks');
> SELECT field FROM tablename;

> |   21 days |
> 
> The output   shows up in days or months but not weeks how do i make 
Internally, INTERVAL is stored as a 12byte tuple (years, months, days,
hours, minutes, seconds, microseconds). It discards any knowledge of
"weeks" (and "centuries" likewise) when it encodes the interval. So
there's no way to force it to say "weeks" back to you. There is no
datestyle that will do it for you, either.

You can MANUALLY extract the number of days in the interval, and divide
by 7 (round up or down, your choice).

SELECT EXTRACT(DAYS FROM INTERVAL '3 WEEKS')

Note, however, that if you define an interval with units greater than
days (i.e. months or years) you'll get nothing, which is reasonable:
months and years do not have fixed numbers of weeks in them.






view thread (2+ messages)

Message-ID: <1124151994.430132baa4e4e@webmail.telus.net>
Permalink:  ../1124151994.430132baa4e4e@webmail.telus.net/
Also on:    postgresql.org/message-id/1124151994.430132baa4e4e@webmail.telus.net

 · 

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: mischa.sandberg@telus.net
  Subject: Re: SQL output
  In-Reply-To: <1124151994.430132baa4e4e@webmail.telus.net>

* 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