有没有办法确定哪些列是JDBC中的SQL聚合函数的结果?

时间:2017-08-17 14:09:53

标签: jdbc google-apps-script

说我有一个SQL语句:

SELECT airport, COUNT(1) as ct FROM airports GROUP BY 1

有没有办法从JDBC getMetaData确定哪些列在GROUP BY

query = 'SELECT airport, COUNT(1) as ct FROM airports GROUP BY 1'
var rs = stmt.executeQuery(query);
var curRow = rs.getMetaData();

1 个答案:

答案 0 :(得分:0)

我在发布后不久就想到了这一点,这可能并不总是有效,但它对我的用例很好。我使用了列的表名并测试了它是否是> 0

query = 'SELECT airport, COUNT(1) as ct FROM airports GROUP BY 1'
var rs = stmt.executeQuery(query);
var curRow = rs.getMetaData();
console.log('getColumnName', curRow.getColumnName(2))
console.log('getColumnLabel', curRow.getColumnLabel(2))
var tabName = curRow.getTableName(2)
console.log('tabName.length', tabName.length)
if (tabName.length > 0) {
  console.log('tabName is legit', tabName)
} else {
  console.log('tabName is not legit', tabName)
}