porsager / postgres

Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare
The Unlicense
7.09k stars 259 forks source link

Dot cannot be used in column name #731

Open Seidko opened 8 months ago

Seidko commented 8 months ago

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"