I try to import a csv file in a table in PostgreSQL 13 and php form ( beginner ).
There are two foreign keys integer type in the table, one can be empty. So when I import the file I have the common message invalid input syntax for type integer
for one of them.
Following this post , NullIf() function seems to be a simple solution.
I can't find the right way to use it in:
$sql = "INSERT INTO activite.us (numus, gidgeo, gidaxe)
VALUES ('".$getData[0]."','".$getData[10]."', NULLIF('".$getData[11]."', '') " ;
The foreign key is the last variable.
'NULLIF("...")'
and some others false combo.How to fix that? Thanks.
(Even if PDO would be better,) an answer is
NULLIF('".$getData[11]."', '')::integer)
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.