【问题标题】:How to make this query return result for a specific column如何使此查询返回特定列的结果
【发布时间】:2011-05-09 03:31:51
【问题描述】:

我有一个这样的查询:-

SELECT count(*) as count FROM pg_attribute, pg_type WHERE attrelid = typrelid and typname = 'table_name' and attname in ('column1','column2','column3','column4')

我正在尝试以这种方式获取“count”列的值(当然是在我执行查询之后):-

$columnExist->getInt('count')

这里的问题是我收到“无效的结果集列:计数”。我不确定这里有什么问题,任何人都可以帮助我。不过,该查询适用于此:-

$columnExist->next() //returns 4

【问题讨论】:

  • count是保留字的问题?试试SELECT count(*) AS c ...$columnExist->getInt('c')

标签: sql postgresql orm


【解决方案1】:

我设法解决了。一个愚蠢的错误。应该按这个顺序执行:-

$columnExist->next();
$columnExist->getInt('count')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多