I'm trying to update
a text type column in Postgres from Node.js
. I would like to append a dynamic string to the data in the text type column.
but I get an error
"error: could not determine data type of parameter $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]);
I've checked out the following links.
Their solution works if I didn't have a dynamic string.
- SQL Server - Adding a string to a text column (concat equivalent)
- How can I add text to SQL Column
- How to prepend a string to a column value in MySQL?
- How can I append a string to an existing field in MySQL?
Please share suggestions. Thanks :)