How to add parameter values to pgadmin sql query?

后端 未结 2 923
一整个雨季
一整个雨季 2021-02-12 14:19

In pgadmin3, I would like to use parameterized queries (to faster debugging, just copy & paste the query from my php file). But I haven\'t found an option to add the values

相关标签:
2条回答
  • 2021-02-12 14:37

    In DBeaver you can use parameters in queries just like you can from code, so this will work:

    select * from accounts where id = :accountId
    

    When you run the query DBeaver will ask you for the value for :accountId and run the query.

    0 讨论(0)
  • 2021-02-12 14:44

    I only know two ways.

    First is to use PREPARED STATEMENT (Example after PostgreSQL Manual):

    PREPARE usrrptplan (int) AS
        SELECT * FROM users u, logs l
        WHERE u.usrid=$1 AND u.usrid=l.usrid AND l.date = $2;
    
    EXECUTE usrrptplan(1, current_date);
    

    PREPARE creates a prepared statement. When the PREPARE statement is executed, the specified statement is parsed, analyzed, and rewritten. When an EXECUTE command is subsequently issued, the prepared statement is planned and executed.

    Prepared statements can take parameters: values that are substituted into the statement when it is executed. When creating the prepared statement, refer to parameters by position, using $1, $2, etc.

    Prepared statements only last for the duration of the current database session. When the session ends, the prepared statement is forgotten, so it must be recreated before being used again.

    Second is to "find-and-replace" $1, $2, .. etc. by proper values. But you want to avoid this one.

    0 讨论(0)
提交回复
热议问题