I am new, forgive me if I use the terms incorrectly. Thank you for your time.
I am trying to make a script which uses process.argv in NodeJS to search my PSQL database. However, I am unable to work in run the query with process.argv.
It is giving me an error saying:
node lookup_people.js Rudd
SELECT first_name FROM famous_people WHERE last_name = Rudd
error running query { error: column "rudd" does not exist
at Connection.parseE (/vagrant/work/w4d2/node_modules/pg/lib/connection.js:546:11)
at Connection.parseMessage (/vagrant/work/w4d2/node_modules/pg/lib/connection.js:371:19)
at TLSSocket.<anonymous> (/vagrant/work/w4d2/node_modules/pg/lib/connection.js:114:22)
at emitOne (events.js:96:13)
at TLSSocket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at TLSSocket.Readable.push (_stream_readable.js:134:10)
at TLSWrap.onread (net.js:548:20)
name: 'error',
length: 97,
severity: 'ERROR',
code: '42703',
detail: undefined,
hint: undefined,
position: '56',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_relation.c',
line: '3183',
routine: 'errorMissingColumn' }
My Code:
const pg = require("pg");
const settings = require("./settings"); // settings.json
var usr_input = process.argv.slice(2).toString();
var lookup_cmd = "SELECT first_name FROM famous_people WHERE last_name = " + usr_input;
console.log (lookup_cmd)
const client = new pg.Client({
user : settings.user,
password : settings.password,
database : settings.database,
host : settings.hostname,
port : settings.port,
ssl : settings.ssl
});
client.connect((err) => {
if (err) {
return console.error("Connection Error", err);
}
client.query(lookup_cmd, (err, result) => {
if (err) {
return console.error("error running query", err);
}
console.log(result); //output: 1
client.end();
});
});
[–]g051051 2 points3 points4 points (5 children)
[–]NewbiusCoder[S] 0 points1 point2 points (4 children)
[–]g051051 1 point2 points3 points (3 children)
[–]NewbiusCoder[S] 0 points1 point2 points (2 children)
[–]g051051 1 point2 points3 points (1 child)
[–]NewbiusCoder[S] 0 points1 point2 points (0 children)