Re: SQL output

From: Mischa Sandberg <mischa(dot)sandberg(at)telus(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: SQL output
Date: 2005-08-16 00:26:34
Message-ID: 1124151994.430132baa4e4e@webmail.telus.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Quoting Simon Law <simonslaw(at)gmail(dot)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.

In response to

  • SQL output at 2005-08-15 23:55:20 from Simon Law

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Fuhr 2005-08-16 00:43:49 Re: Problem with a Pettern Matching Check
Previous Message Tom Lane 2005-08-16 00:21:23 Re: Problem with a Pettern Matching Check