postgres
postgres copied to clipboard
Dot cannot be used in column name
description
Hello! For some reason. I need to use .
in my column name, but I found a problem. This is my code:
import postgres from 'postgres'
const sql = postgres({ /* options */ })
// table has "meta.a" column
const data = { 'meta.a': 'text' }
await sql`INSERT INTO ${this.sql('object')} ${data} RETURNING *`
// throw error `PostgresError: column "meta" of relation "object" does not exist`
It is weird. PostgreSQL supports using .
in column name.
I read the code and found this:
https://github.com/porsager/postgres/blob/61c4d5b1d840ed1e3e0f8e84556544a33ee04149/src/types.js#L216-L218
It seems like these code replace all .
to "."
, this doesn't look like a correct behavior.
expected behavior
"meta.a"
should remain as-is.
meta.a
should be escaped to "meta"."a"