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]);
다음 링크를 확인했습니다.
그들의 솔루션은 동적 문자열이 없으면 작동합니다.
제안을 공유하십시오. 감사 :)
함수 CONCAT
가 가져 오는 데이터 유형에 대해 확신하지 못합니다. ::text
도움이되는 명시 적 유형 캐스팅 :
CONCAT($1::text, searchqueries)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다