Re: [SQL] Typecasting datetype as date. How do I cope with NULLs? - Mailing list pgsql-sql

From Sferacarta Software
Subject Re: [SQL] Typecasting datetype as date. How do I cope with NULLs?
Date
Msg-id 19557.981127@bo.nettuno.it
Whole thread Raw
In response to [SQL] Typecasting datetype as date. How do I cope with NULLs?  (Stuart Rison <stuart@ludwig.ucl.ac.uk>)
List 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'-



pgsql-sql by date:

Previous
From: sqyang
Date:
Subject: the differences between semaphores and spinlocks
Next
From: Andreas Kostyrka
Date:
Subject: Large Objects, anyone?