porsager / porsager/postgres

Greedy "select" builder?

Open
#774 0 comments 0 reactions 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

Given

const data = { name: "foo" }

The following

with cf as (insert into app.custom_field as cf ${sql(data)} returning cf) ...

is translated to

with cf as (insert into app.custom_field as cf $1 as \"name\" returning cf) ...

while I expect vanilla insert-like expansion like

with cf as (insert into app.custom_field as cf (name)values($1) returning cf) ...

Traces led to as cf token forces the statement to be treated as "select" builder, not "insert" one.

Please consider fixing or pointing out how to gracefully work this around.

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

Reproduce the issue with the shown data object and SQL template, then inspect the builder path that classifies the as cf token. Done when this form expands to (name)values($1) like the expected SQL without breaking the surrounding CTE and returning clause.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.