PostgreSQL: Select where timestamp is empty
I have a query that looks like the following:
SELECT * FROM table WHERE开发者_如何学C timestamp = NULL;
The timestamp column is a timestamp with time zone data type (second type in this table). This is in PostgreSQL 8.4.
What I'm trying to accomplish is to only select rows that have not had a timestamp inserted. When I look at the data in pgAdmin the field is empty and shows no value. I've tried where timestamp = NULL
, 'EPOCH'
(which you would think would be the default value), a valid timestamp of zeros (0000-00-00 00:00:00-00
, which results in a out of range error), the lowest date possible according to the docs (January 1, 4713 BC
) and a blank string (''
, which just gets a data type mismatch error). There also appears to be no is_timestamp()
function that I can use to check if the result is not a valid timestamp.
So, the question is, what value is in that empty field that I can check for?
Thanks.
EDIT: The field does not have a default value.
null
in SQL means 'unknown'.
This means that the result of using any comparison operator, like =
, with a null
is also 'unknown'.
To check if a column is NULL
(or not NULL
), use the special syntax of IS NULL
(or IS NOT NULL
) instead of using =
.
Applying that to your statement,
SELECT * FROM table WHERE timestamp IS NULL;
should work.
精彩评论