Share On Twitter Facebook Google+ LinkedIn Pinterest Tumblr Reddit
Question

error: syntax error at or near "s"

Tags: postgresql node.js
Date:
Status:Unresolved
Question Id:65

I am working on node.js and postgresql and I got an error :

error: syntax error at or near "s"

How can I solve it ?

Answer
Date:
Correct:No

Did you paste this from somewhere? Check and replace your quote character, you're using an invalid character (e.g.  instead of ') for quoting.

Answer
Date:
Correct:No

In the INSERT query, add the string values in quotes

const insertData = `
    INSERT INTO authors (id, author_name, author_slug) 
    VALUES 
    ('${authorID}', '${authorName}', '${authorSlug}');`;  // added the quotes
Answer
Date:
Correct:No

I found the error. It's not the query but the error was my setup of pool.query. I just forget adding comma after the query and before the values. hehe stupid me before: pool.query(query[.. after: pool.query(query,[..

Answer
Date:
Correct:No

Aliasing the table you're inserting into was only added in Postgres 9.5 (compare Postgres 9.5's documentation to 9.4's documentation. Since the columns in the returning clause refer to the inserted table anyway, you could just as easily do without it:

insert into "public"."mission_batches"
  ("micro_task_id", "is_active", "created_at", "updated_at") 
values 
  ('7e1cc9e8-fc11-409b-865e-3bf08e6ca924', false,
   timestamp '2016-10-05 21:47:13.061', timestamp '2016-10-05 21:47:13.061') 
returning 
  "id", "micro_task_id", "is_active", "created_at", "updated_at"

Your Answer

Review Your Answer