Вставка данных в PostgreSQL с помощью Google Trends API - PullRequest
4 голосов
/ 31 января 2020

Я получил данные из Google Trends API, и теперь я пытаюсь вставить их в базу данных, но одновременно вставляется только одна строка, и я хочу вставить все строки в базу данных.

try {

var res = await googleTrends.interestByRegion({keyword:keyword,geo:"US-"+state}); //resolution:keyword
res = JSON.parse(res);
// for debugging.
//console.log(res);
if("default" in res){
if("geoMapData" in res["default"]){
for(var x in res["default"].geoMapData){
var row = res["default"].geoMapData[x];

if("geoName" in row && "value" in row){
// console.log(" - " + row.geoName + "\t\t" + row.value);
console.log(">>>>>>>>>>>>>>>>>>",x,row.geoName + row.value)

//insert statement
var name1 = [row.geoName]
// name1.push([keyword,row.geoName])
// var name2 = [row.geoName]

pool.query("INSERT INTO practice(state,keyword) VALUES($1)",name1,(err, res) => {
console.log(err, res);
// pool.end(() => {

// console.log('pool has ended')
//})
});

Я получаю эту ошибку после компиляции.

error: INSERT has more target columns than expressions
at Connection.parseE (/home/abc/Desktop/node2/node_modules/pg/lib/connection.js:604:13)
at Connection.parseMessage (/home/abc/Desktop/node2/node_modules/pg/lib/connection.js:403:19)
at Socket.<anonymous> (/home/abc/Desktop/node2/node_modules/pg/lib/connection.js:123:22
...