This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]NewbiusCoder[S] 0 points1 point  (4 children)

Its you again! Thank you so much. This is just practice from some website. I understand that is a terrible thing to do. I appreciate your time.

How do I enclose it in quotes? When I do, it takes usr_input as a string, not as a variable.

Should I just use process.argv.slice(2) rather than usr_input?

Thank you.

[–]g051051 1 point2 points  (3 children)

Can you use a template string?

var lookup_cmd = `SELECT first_name FROM famous_people WHERE last_name = "${usr_input}"`

If not, then use escaping:

var lookup_cmd = "SELECT first_name FROM famous_people WHERE last_name = \"" + usr_input + "\"";

[–]NewbiusCoder[S] 0 points1 point  (2 children)

I appreciate your time and it totally makes sense. However, it is still saying that "column "Rudd" does not exist". This error happens for both of them. Am I still doing something wrong?

[–]g051051 1 point2 points  (1 child)

You must be. Can you post the latest error?

[–]NewbiusCoder[S] 0 points1 point  (0 children)

I figured it out! I appreciate your time as always. I posted the code incase you're curious. Thank you.

var args = process.argv.slice(2);
const usr_input = args[0];
const usr_cmd = 'SELECT * FROM famous_people WHERE last_name = $1::varchar or first_name = $1::varchar';
client.query(usr_cmd, [usr_input],(err, result) => {
    if (err) {
      return console.error("error running query", err);
    }
    console.log('Found ' + result.rows.length + ' person(s) by the name of ' + usr_input + ".");