I'm trying to get the column name from below query,
SELECT
category as c1,
forecast_2016,
category,
rowcount,
item_number,
rowcount,
category,
avg_demand_2014_2015,
category,
avg_spend_2014_2015,
avg_demand_2014_2015,
avg_spend_2014_2015,
demand_2015
FROM
ag_instrument_portfolio_master LIMIT 1
Postgres version is 9.3 and Java version 1.7, java implementation is below.
stmt = con.createStatement();
rs = stmt.executeQuery(query.toString());
ResultSetMetaData columnsMetadata = rs.getMetaData();
int i = 0;
while (i < columnsMetadata.getColumnCount()) {
i++;
System.out.println("Name: " + columnsMetadata.getColumnName(i));
System.out.println("Label: " + columnsMetadata.getColumnLabel(i));
}
The output is
Name: c1
Label: c1
But, expected is
Name: category
Label: c1
Given the comment in the pgsql-jdbc mailing list here, it appears that what you're seeing is the "as designed" behaviour of the PostgreSQL JDBC driver:
This is a limitation of the information the driver gets back from the server, it only returns the 'label' which the driver then uses for both columnname and label.
As with many other aspects of JDBC, the behaviour of a given feature can often vary depending on the implementation of a specific JDBC driver.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With