cds-dbs icon indicating copy to clipboard operation
cds-dbs copied to clipboard

Postgres Quoted/Upper-case Column Alias in SELECT output doesn't seem correct

Open jung-thomas opened this issue 1 year ago • 0 comments

Description of erroneous behaviour

I'm testing on CAP 7.2.0 and @cap-js/postgres 1.2.1

I'm performing a SELECT and want to alias the column names to upper case. In both HANA and SQLite the query works just by passing upper case literal to the as parameter

SQLite example that works as expected

let dbQuery = SELECT
            .columns({ref:["name"],as:'TABLE_NAME'})
            .from("sqlite_schema")
            .where({ type: 'table', name: { like: tableName } })
            .limit(super.getPrompts().limit)
        base.debug(JSON.stringify(dbQuery))
        let results = await this.getDB().run(dbQuery)

https://github.com/SAP-samples/hana-developer-cli-tool-example/blob/8b6eab19d38361c5b59cf7a82f2ded8ed27b7e7b/utils/database/sqlite.js#L15

Name is in the results as TABLE_NAME image

But doing the same when targeting Postgres doesn't work the same. The resulting column alias is still lower case. So, I tried quoting within the literal with ". That did produce an all-uppercase column name but, that name also contains the " in the output. I can't get the same output as HANA and SQLite with the column alias in this example.

Postgres example

     let dbQuery = SELECT
            .columns(
                {ref:["table_schema"],as: `"SCHEMA_NAME"` },
                {ref:["table_name"],as:'TABLE_NAME'} )
            .from("tables")
            .where({ table_schema: this.#schema, table_name: { like: tableName }, table_type: 'BASE TABLE' })
            .limit(super.getPrompts().limit)

            base.debug(JSON.stringify(dbQuery))
        let results = await this.getDB().run(dbQuery)

https://github.com/SAP-samples/hana-developer-cli-tool-example/blob/8b6eab19d38361c5b59cf7a82f2ded8ed27b7e7b/utils/database/postgres.js#L18

TABLE_NAME is returned all lower case and SCHEMA_NAME is upper but has the " in the output column: image

Details about your project

SAP HANA Developer Command Line Interface https://github.com/SAP-samples/hana-developer-cli-tool-example
Node.js version v20.3.1
@sap/cds 7.2.0
@sap/cds-compiler 4.2.2
@sap/cds-dk 7.2.0
@cap-js/postgres 1.2.1
@cap-js/sqlite 1.2.1

jung-thomas avatar Sep 08 '23 16:09 jung-thomas