node.jspostgresqlnode-postgres

AS statement ignoring cases in PSQL


We are using the Node Postgres client to run some queries on our database, like:

await client.query('SELECT A.date_time AS dateTime FROM A')

the problem is that returned value for the row comes as:

Expected:{
  dateTime: '2009-06-16 11:00:00'
}

Received: {
  datetime: '2009-06-16 11:00:00'
}

is this a bug or are we missing a configuration somewhere?


Solution

  • SQL is case sensitive, but everything that is not a string literal or a quoted identifier is case folded. The SQL standard prescribes case folding to upper case, but PostgreSQL folds to lower case.

    If you want case to be preserved in an identifier like dateTime, you have to surround it with double quotes: "dateTime"