Reputation: 711
Probably a very simple answer that is making me a bit crazy.
I'm using C# and npgsql to connect to a PostgreSQL database.
I'm trying to either SELECT or INSERT, where the log_date field (Type is date) doesn't have any date in it. Its not set to allow nulls.
I have tried:
var pgCommand = new NpgsqlCommand("SELECT * FROM tableX WHERE log_date = '';", connection);
var pgCommand = new NpgsqlCommand("SELECT * FROM tableX WHERE log_date = \"\";", connection);
var pgCommand = new NpgsqlCommand("SELECT * FROM tableX WHERE log_date = NULL;", connection);
var pgCommand = new NpgsqlCommand("SELECT * FROM tableX WHERE log_date = null;", connection);
var pgCommand = new NpgsqlCommand("SELECT * FROM tableX WHERE log_date = '\"\"';", connection);
If I do a SELECT and write the data to the console, nothing shows up under the date, which is correct as there is nothing in the log_date field.
How the heck do I check for an empty date?
Thanks,
Neill
Upvotes: 0
Views: 614
Reputation: 63772
It if allows null
, you can use is null
, e.g. log_date is null
. If it doesn't, you're supposed to give it some value - that will usually work out to some default either at the database level or the application level (.NET's default being 01/01/0001 00:00:00
). However, this just hints at a deeper design issue - how come "there's no value" in a column that's not allowed to not have a value?
Upvotes: 2