【问题标题】:How to check if prepared statement already exists in Ruby?如何检查 Ruby 中是否已经存在准备好的语句?
【发布时间】:2014-08-14 09:44:27
【问题描述】:

在 Ruby 中使用 PG Gem for Postgresql,您将如何检查准备好的语句是否已经存在?

【问题讨论】:

标签: ruby postgresql prepared-statement pg


【解决方案1】:

您可以查询 pg_prepared_statements 视图以查看是否使用了该名称: http://www.postgresql.org/docs/9.2/interactive/view-pg-prepared-statements.html

感谢在 cmets 中回答的 akonsu。

【讨论】:

    【解决方案2】:

    您也可以通过捕获调用 describe_prepared 时遇到的错误来做到这一点

    statement_exists = true
    begin 
      connection.describe_prepared(statement_name)
    rescue PG::InvalidSqlStatementName
      statement_exists = false
    end
    

    【讨论】:

      猜你喜欢
      • 2010-11-14
      • 1970-01-01
      • 1970-01-01
      • 2014-05-09
      • 1970-01-01
      • 2014-12-16
      • 2015-12-22
      • 1970-01-01
      • 2011-11-28
      相关资源
      最近更新 更多