Important: Please read the Qt Code of Conduct -

Getting error 42601 when running procedure in PostgreSQL

  • I've deleted this and created a new topic with a minimal example included.

    I've created a program that connects to a PostgreSQL database and now I'm trying to call a procedure (that works, I've tested it directly in the database)
    but this fail

    QSqlQuery query(m_db);
    query.prepare(QString("call add_new_task(?,?,?,?,?, ?, ?)"));
    query.bindValue(0, task.get_c());
    query.bindValue(1, task.get_d());
    query.bindValue(2, task.get_p());
    query.bindValue(3, task.get_e());
    query.bindValue(4, task.get_after());
    query.bindValue(5, task.get_before());
    query.bindValue(6, 0, QSql::InOut);
    if (query.exec())  { ... this is not run ... }
    else { ... this is run ... }

    and it fails with the error

    QSqlError("42601", "QPSQL: Unable to create query", "ERROR:  syntax error at or near \"(\"\nLINE 1: EXECUTE  ('C X', 'D X', 5, 8, '2020-10-31', ...\n                ^\n(42601)")

    In the postgresql logs I see

    syntaxerror at or near  "call" at character 25
    PREPARE qpsqlpstmt_1 AS call add_new_task($1, $2, $3, $4, $5, $6, $7)
    ERROR:  syntaxerror at or  near "(" vid tecken 10
    STATEMENT:  EXECUTE  ('Caption X', 'Description X', 5, 8, '2020-10-31', '2120-10-31', 0)

    How can I find the error? Please help me, I'm stuck.

Log in to reply