说我有一个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();
答案 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)
}