Finding which DATE columns have no time data using TRUNC I'm in the process of converting an Oracle db to a PostgreSQL one.

The script I used converted all Oracle's DATE columns into TIMESTAMPS, but I suspect that most of those do not hold any time data and could be converted to PostgreSQL DATE data type.

To make sure of it, I used the following query on Oracle:

SELECT myDate, TRUNC(myDate, 'DDD') from myTable where TRUNC(myDate, 'DDD') &lt;&gt; myDate;


This seems to work fine; in most cases I get 0 lines returned. For some tables though, I get a handfull of results that make no sense:

trunc(…     myDate
17/07/95    17/07/95
24/08/42    24/08/42
29/06/02    29/06/02
26/07/88    26/07/88


Update: My SQL client wasn't showing the full values, some lines did have some time data. The above lines, however are actually:

trunc(…                myDate
17/07/5595 00:00:00    17/07/5595 00:00:00
24/08/5542 00:00:00    24/08/5542 00:00:00
29/06/5602 00:00:00    29/06/5602 00:00:00
26/07/5588 00:00:00    26/07/5588 00:00:00


Clearly those are typos, but I don't know why they would be returned by my query.
This is because the data representation of dates depends on your NLS settings.

You can change the representation of dates for your current SQL statements before you issue your first command by using the following command:

alter session set nls_date_format = 'yyyy-mm-dd hh24:mi:ss';


Or seeing as you are using the slash notation:

alter session set nls_date_format = 'dd/mm/yyyy hh:mi:ss am';


If you then having a column containing a date format, then it should be returned as:

29/06/2002 1:50 pm


References


Setting Up a Globalization Support Environment (Oracle Docs)