Re: [SQL] Typecasting datetype as date. How do I cope with NULLs?

From: Sferacarta Software <sferac(at)bo(dot)nettuno(dot)it>
To: pgsql-sql(at)postgresql(dot)org, Stuart Rison <stuart(at)ludwig(dot)ucl(dot)ac(dot)uk>
Subject: Re: [SQL] Typecasting datetype as date. How do I cope with NULLs?
Date: 1998-11-27 12:23:31
Message-ID: 19557.981127@bo.nettuno.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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'-

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Andreas Kostyrka 1998-11-27 19:51:56 Large Objects, anyone?
Previous Message Stuart Rison 1998-11-26 15:55:42 [SQL] Typecasting datetype as date. How do I cope with NULLs?