Search code examples
postgresqldbeaver

Executing a prepared statement is not returning data


I am creating Postgresql prepared statement as follows.

PREPARE fetch_users AS SELECT *
FROM "user" u
WHERE 
    u.email = $1
LIMIT 1;

It is getting successfully created, and I can see it in the pg_prepared_statements table.

But, when I do,

EXECUTE fetch_users('testemail@test.com');

I'm getting no result from the database, although the select query returns the result when run independently.

Am I using prepared statements correctly?

Note: I am using PostgreSQL version: 15.1 with Dbeaver. When I run the prepared statement I get this prompt. enter image description here

I enter nothing for the value and select Ok. When the statement gets executed, this is the output.

enter image description here

It seems the null is inserted in the prepared statement.


Solution

  • in the prompt, you need to click on the ignore button:

    enter image description here

    This way it will not put any predefined parameter values in your prepared statements.