Need help with sql select on null dates!

Started by Jeff Sackstederover 23 years ago4 messagesgeneral
Jump to latest
#1Jeff Sacksteder
jwsacksteder@ramprecision.com

I'm having trouble doing a select on empty date fields.

Suppose my table is composed of employee_number(char), hire_date(date), and
termination_date(date).
I would expect to be able to say:

'select * from employee_tables where termination_date = null'
or:
'select * from employee_tables where isfinite(termination_date) <>
1'

...but no luck. What is the proper way to select undefined dates?

#2Henshall,	Stuart - Design & Print
SHenshall@westcountry-design-print.co.uk
In reply to: Jeff Sacksteder (#1)
Re: Need help with sql select on null dates!

Jeff Sacksteder wrote:

I'm having trouble doing a select on empty date fields.

Suppose my table is composed of employee_number(char),
hire_date(date), and termination_date(date).
I would expect to be able to say:

'select * from employee_tables where termination_date = null' or:
'select * from employee_tables where
isfinite(termination_date) <>
1'

...but no luck. What is the proper way to select undefined dates?

NULLs are unknown and therefore there equality can not be tested.
select * from employee_tables where termination_date is null;
ought to work however
hth,
- Stuart

#3Diogo Biazus
diogo@ikono.com.br
In reply to: Jeff Sacksteder (#1)
Re: Need help with sql select on null dates!

Jeff Sacksteder wrote:

I'm having trouble doing a select on empty date fields.

Suppose my table is composed of employee_number(char), hire_date(date), and
termination_date(date).
I would expect to be able to say:

'select * from employee_tables where termination_date = null'

Isntead of '= null' you should use the 'IS NULL' operator.
For example:

'select * from employee_tables where termination_date is null'

--
Diogo de Oliveira Biazus
diogo@ikono.com.br
Ikono Sistemas e Automa��o
http://www.ikono.com.br

#4Bruno Wolff III
bruno@wolff.to
In reply to: Jeff Sacksteder (#1)
Re: Need help with sql select on null dates!

On Tue, Nov 26, 2002 at 08:47:02 -0500,
Jeff Sacksteder <jwsacksteder@ramprecision.com> wrote:

I'm having trouble doing a select on empty date fields.

Can you be more precise in what you mean by "empty"? Do you mean NULL?

Suppose my table is composed of employee_number(char), hire_date(date), and
termination_date(date).
I would expect to be able to say:

'select * from employee_tables where termination_date = null'
or:
'select * from employee_tables where isfinite(termination_date) <>
1'

...but no luck. What is the proper way to select undefined dates?

Neither of the about will return rows with termination_date null in recent
versions of postgres. If the value you are trying to match is null, then
using "is null" instead of "= null".