我试图在update
中Postgres from Node.js
文字类型列。我想在文本类型列的数据中添加动态字符串。
但是我收到了错误
"错误:无法确定参数$ 1"
的数据类型
var pg = require('pg');
var connectionString = process.env.DATABASE_URL || "pg://admin:guest@localhost:5432/imagesearchexperiment";
var client = new pg.Client(connectionString);
client.connect();
client.query("DROP TABLE IF EXISTS imagesearchexperiment");
client.query("CREATE TABLE IF NOT EXISTS imagesearchexperiment(ipAddress varchar(64), searchqueries text)");
client.query("INSERT INTO imagesearchexperiment(ipAddress, searchqueries) VALUES($1, $2)",["ipAddress1","query1<>query2<>query3"]);
client.query("INSERT INTO imagesearchexperiment(ipAddress, searchqueries) VALUES($1, $2)",["ipAddress2","query1<>query2<>query3"]);
client.query("INSERT INTO imagesearchexperiment(ipAddress, searchqueries) VALUES($1, $2)",["ipAddress3","query1<>query2<>query3"]);
var searchQuery = "query4";
var ip = "ipAddress3";
// The following line is causing an error - error: could not determine data type of parameter $1
client.query("UPDATE imagesearchexperiment SET searchqueries = CONCAT($1, searchqueries) WHERE ipAddress = $2", [searchQuery, ip]);
&#13;
我已查看以下链接。
如果我没有动态字符串,他们的解决方案就有效。
答案 0 :(得分:0)
函数CONCAT
不确定它获取的数据类型。显式类型转换为::text
将有助于:
CONCAT($1::text, searchqueries)
答案 1 :(得分:0)
UPDATE imagesearchexperiment SET searchqueries = '"+ searchqueries="' WHERE ipAddress = "'+ ip+'"