A
A
Alexander2021-01-19 10:36:53
PostgreSQL
Alexander, 2021-01-19 10:36:53

What's wrong with the request, error: "error: syntax error at end of input"?

There is a query for MySQL: Trying to run it in pg throws an error What's wrong?
SELECT * FROM users WHERE user_id = ?
error: syntax error at end of input

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dr. Bacon, 2021-01-19
@Alexandre888

Facepalm.

A
andrewpilikin, 2022-03-05
@andrewpilikin

There is an error in the syntax, for example the table name may contain a space, or the string may have a character that is misinterpreted.
For example, the Delit operation:
This syntax does not work, it’s clear that when you insert a query into the database tool, kuti generates the same error:

const QString request="DELETE FROM \"" + tableName + "\" WHERE name=\""+rowName+"\";";

This syntax works:
const QString request="DELETE FROM \"" + tableName + "\"" +
            " WHERE name=\'"+ rowName +"\'";

And an example with an insert:
Doesn't work:
const QString request="INSERT INTO \"" + tableName +"\" ( name ) VALUES ( "+ rowName + " );";

It seems to work, copying everything to the DataGrid is done:
const QString request="INSERT INTO \"" + tableName+ "\" (name) "+
    "VALUES ('"+ rowName+ "');  ";

And again no.
Here is a working version:
const QString request="INSERT INTO \""+ tableName+"\""+
            " ( name ) VALUES (?)";
    query.prepare(request);
    query.bindValue(0, rowName);

Sometimes you can't guess why a request doesn't work. A similar, one to one, copied to pgAdmin or Datagrid runs with a bang. That is why instead of pure sql query it is better to use ORM

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question