我正在对Sequel执行一个简单的查询,如下所示:
result = db.execute("SELECT some_int_colum FROM some_system_table WHERE some_column = 'some_value';")
在psql会话中,它返回预期的值,但是当通过Sequel Postgres适配器运行时,它返回结果行数,而不是值。
来源(参考):
# Execute the given SQL with this connection. If a block is given, # yield the results, otherwise, return the number of changed rows.
这清楚地解释了为什么,但是在这种情况下如何给execute方法一个块呢?
Dataset#fetch
(reference)是执行任意sql并返回单个或一组值的更合适的方法。在上面的示例中,只期望一个返回值,它看起来像这样:
result = db.fetch("SELECT some_int_colum FROM some_system_table WHERE some_column = 'some_value'").all.first.values.first