Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Getting error 42601 when running procedure in PostgreSQL
Qt 6.12 LTS is out! See what's new in the release blog

Getting error 42601 when running procedure in PostgreSQL

Scheduled Pinned Locked Moved Solved General and Desktop
sql
1 Posts 1 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    OpenGL
    wrote on last edited by OpenGL
    #1

    I've deleted this and created a new topic with a minimal example included.
    https://forum.qt.io/topic/120460/minimal-sql-program-that-fails-what-is-wrong-with-it

    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.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt
    • Unsolved