Reputation: 1
I am running a panda read sql select statement and wish to exclude rows from my output where a certain field is NULL.
In standard SQL (Oracle, mySql, ms_sql) I would use where field_name is not null
. I have attempted to use that code in my pd.read_sql but the result returns null values for the field I am trying to limit the output from, based on null values. My current workaround is to use length(field_name) > 0
.
My example code is here:
import pandas as pd
import time
Result3 = pd.read_sql("Select gcdu_flatten.cbid_code, gcdu_flatten.incorporation_country, gcdu_flatten.gid_original, gcdu_flatten.local_cust_id, gcdu_flatten.saracen_id "
" FROM rm_views_uat_wave.gcdu_flatten "
" WHERE gcdu_flatten.etlmonth in ('2024-04-30') "
#" and gcdu_flatten.saracen_id is not null " ##This statement does NOT limit the data output to rows where the 'saracen_id is not null'
" and length(gcdu_flatten.saracen_id) > 0 " ##My current workaround to exclude null values for the field 'saracen_id'
, conn)
Any suggestions are most welcome. Thanks!
Upvotes: 0
Views: 51