Hi I am working with Python, already connected to Postgres, I want to insert a dataframe into a postgres table if exists do an update.
My issue is that the script is sending for Null values None, and postgres is showing me an issue with None, if I use replace is sending 'NULL' as string, how I can deal with NULL valueS? I am using SQLALCHEMY
sqlconn='postgresql://postgresql:mypass@localhost:port/db'
db = create_engine(sqlconn, pool_recycle=3600);
conn.execute(f"INSERT INTO mytable (id,name,address,created_by,created_date,active) VALUES {','.join([str(i) for i in list(mydataframe.to_records(index=False))])} ON CONFLICT (id) DO UPDATE SET name = EXCLUDED.name, address = EXCLUDED.address,created_by=EXCLUDED.created_by, created_date=EXCLUDED.created_date, active=EXCLUDED.active ;")
conn.close()
Error from Postgres:
ERROR: column "none" does not exist
LINE 6: (None,
Sample
INSERT INTO mytable (id,name,address,created_by,created_date,active)
VALUES (1,'Carlos','Address XY','user',None,True);
How I can send a NULL besides a None?
Regards
I already Tried with Nan values, Sending 'NULL' with a replace but doesn't work at all.