Reputation: 110093
Is there a better way to do the following to check if a column is not empty/null?
(v.file_name is not null and v.file_name != ''
and v.file_last_known_location is not null and v.file_last_known_location != '')
Upvotes: 0
Views: 184
Reputation: 70513
I think this is clearer
COALESCE(v.file_name,'') != '' AND COALESCE(v.file_last_known_location,'') != ''
On some systems this may perform worse (as @sgeddes notes) against indexed columns.
Upvotes: 1
Reputation: 93694
I would say even though the current query looks clumsy, it will out perform the suggested answer when you have index on file_name
and file_last_known_location
.
The usage of function
in Where
clause will restrict optimizer from using Index
. So better to use original query
(v.file_name is not null and v.file_name != ''
and v.file_last_known_location is not null and v.file_last_known_location != '')
Upvotes: 1