Am doing bulk inserts where some columns can be represented by empty string ''
and I want to convert that empty string to a Postgresql DB Null value
If I was using psycopg2's copy_from
, its easy and i'd have something like this:
copy_from(file_like_object, table, sep='|', null='', size=8192, columns=None)
The null=''
would automatically convert the empty strings into DB Nulls.
However, right now am using SQlAlchemy. Does it have a similar magic parameter to its insert statement to convert empty strings to Null?
By insert statement I mean sqlalchemy core's .insert() as seen in example below
user_table = Table('user_table', metadata, autoload=True, autoload_with=engine)
sql = user_table.insert().values(sql_binder)
conn = engine.connect()
trans = conn.begin()
conn.execute(sql, db_users)
trans.commit()
conn.close()
I know I can iterate through each value and check if its an empty string and then pass Python's None
but that is a lot of iterations and I want to avoid that.