From: Sferacarta Software <sferac@bo.nettuno.it>
To: pgsql-sql@postgresql.org, Stuart Rison <stuart@ludwig.ucl.ac.uk>
Subject: Re: [SQL] Typecasting datetype as date. How do I cope with NULLs?
Date: Fri, 27 Nov 1998 13:23:31 +0100
Message-ID: <19557.981127@bo.nettuno.it> (raw)
References: <l03110700b2831665de7a@[128.40.242.190]>
Hello Stuart,
giovedì, 26 novembre 98, you wrote:
SR> Dear All,
SR> For those of you who don't want to wade through the details, here's the
SR> question: "How do I get the date portion of a datetime field for ALL
SR> ENTRIES in a table regardless of whether the entry is NULL or not? (N.B.
SR> Typecasting a datetime NULL as date generates an error)"
Table = a
+----------------------------------+----------------------------------+-------+
| Field | Type | Length|
+----------------------------------+----------------------------------+-------+
| dt | datetime | 8 |
| i | int4 | 4 |
+----------------------------------+----------------------------------+-------+
prova=> select * from a;
dt |i
----------------------+-
1998-12-26 16:35:23+01|1
1998-12-25 00:00:00+01|2
1998-12-27 00:00:00+01|3
(3 rows)
prova=> insert into a values (null,4);
INSERT 553697 1
prova=> select * from a;
dt |i
----------------------+-
1998-12-26 16:35:23+01|1
1998-12-25 00:00:00+01|2
1998-12-27 00:00:00+01|3
|4
(4 rows)
prova=> select *, extract(day from dt) from a;
dt |i|date_part
----------------------+-+---------
1998-12-26 16:35:23+01|1| 26
1998-12-25 00:00:00+01|2| 25
1998-12-27 00:00:00+01|3| 27
|4|
(4 rows)
-Jose'-
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: sferac@bo.nettuno.it, stuart@ludwig.ucl.ac.uk
Subject: Re: [SQL] Typecasting datetype as date. How do I cope with NULLs?
In-Reply-To: <19557.981127@bo.nettuno.it>
References: <l03110700b2831665de7a@[128.40.242.190]> <19557.981127@bo.nettuno.it>
* 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