porsager / porsager/postgres

Dot cannot be used in column name

Open
#731 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
8.7k
Forks
374
Avg merge
11d 16h
Merged PRs (30d)
1

Description

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"

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at src/types.js lines 216-218, which the report identifies as the identifier-escaping logic, and reproduce the INSERT using a column named "meta.a" and a nested identifier meta.a. Done means quoted column names containing dots remain a single identifier while unquoted dotted names become separate quoted identifiers, matching the expected SQL behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, postgresql
Domain
databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.