pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedSQL output
2+ messages / 2 participants
[nested] [flat]
* SQL output
@ 2005-08-15 23:55 Simon Law <simonslaw@gmail.com>
2005-08-16 00:26 ` Re: SQL output Mischa Sandberg <mischa.sandberg@telus.net>
0 siblings, 1 reply; 2+ messages in thread
From: Simon Law @ 2005-08-15 23:55 UTC (permalink / raw)
To: pgsql-sql
CREATE TABLE tablename (field INTERVAL);
INSERT INTO tablename VALUES('3 weeks');
SELECT field FROM tablename;
_________
| field |
|--------------|
| 21 days |
|________|
The output shows up in days or months but not weeks how do i make
it output in weeks?
Any help with this will be greatly appreciated
P.S.
Best postgresql book?
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: SQL output
2005-08-15 23:55 SQL output Simon Law <simonslaw@gmail.com>
@ 2005-08-16 00:26 ` Mischa Sandberg <mischa.sandberg@telus.net>
0 siblings, 0 replies; 2+ messages in thread
From: Mischa Sandberg @ 2005-08-16 00:26 UTC (permalink / raw)
To: pgsql-sql
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.
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2005-08-16 00:26 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-08-15 23:55 SQL output Simon Law <simonslaw@gmail.com>
2005-08-16 00:26 ` Mischa Sandberg <mischa.sandberg@telus.net>
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