[英]Postgres update with case causing error "could not determine data type of parameter $3"
I have an issue with our golang programs when querying sql statement as below.我在查询 sql 语句时遇到了我们的 golang 程序问题,如下所示。
"database/sql" “数据库/sql”
sqlStatement := `
UPDATE user_posts SET
content = $2,
post_image = CASE WHEN ($3 IS NULL) THEN post_image ELSE $3 END,
updated_at = NOW()
WHERE id = $1
`
Found the answers parameter $3 cannot compare with clause "IS NULL" fixed as below.发现答案参数 $3 无法与固定如下的子句“IS NULL”进行比较。
sqlStatement := `
UPDATE user_posts SET
content = $2,
post_image = CASE WHEN $3 != '' THEN $3 ELSE post_image END,
updated_at = NOW()
WHERE id = $1
`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.