deliverr / data-knex-snowflake-dialect

knex.js dialect for the Snowflake data warehouse
MIT License
16 stars 26 forks source link

Snowflake is case sensitive! #15

Open pragi-balasubramanian-alation opened 3 years ago

pragi-balasubramanian-alation commented 3 years ago

Snowflake is case-insensitive if you use identifier without double quotes, But its case sensitive with double quotes. (https://docs.snowflake.com/en/sql-reference/identifiers-syntax.html)

But data-knex-snowflake-dialect always emits query with columns that are in upper-case.

For example:

const connection = knex({
  client: SnowflakeDialect,
})

const builder = connection('TABLE1')
  .withSchema('SCHEMA1')
  .select({
       'Id': 'id'
  })

Expected: select "TABLE1"."id" as "Id" from "SCHEMA1"."TABLE1" Actual: select "TABLE1"."ID" as "ID" from "SCHEMA1"."TABLE1"

Note: alias name and column name - both have to be case sensitive.

Workaround:

const builder = connection('TABLE1')
  .withSchema('SCHEMA1')
  .select([
    knex.ref(
        knex.raw('id')
    ).as(
        knex.raw('Id')
    )])

With this, I am able to make column name and alias however i want