简体   繁体   中英

Is there a function in SQL to replace an insert sql query values 'NULL' as NULL or 'unknown' as NULL

I have constructed an insert sql query in Python. In python code, I have given 'NULL' string for a column value. While executing the sql query, database is inserted with value 'NULL' for the column. I want the column to be updated with NULL value. Similarly, I want to execute an insert sql query with value NULL for a value 'Unknown' constructed in python.

Here is my sql query:

INSERT INTO lookup SELECT 'Unknown' as dc, 'NULL' as URL FROM lookup_hierarchy lh WHERE lh.location = 'Arizona';

How to replace 'NULL' with NULL in sql ? How to replace 'unknown' with NULL in sql ?

您可以使用条件,该条件始终返回NULL例如:

INSERT INTO lookup SELECT IF(1, NULL, 'Unknown') as dc, IF(1, NULL, 'null') as URL FROM lookup_hierarchy lh WHERE lh.location = 'Arizona';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM