porsager / porsager/postgres

Syntax error at or near "$1" at "Query parameters"

Open
#772 5 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

Hello. I'm trying to make a dynamic request. I try to do it as closely as possible to the documentation, but I still get syntax error at or near "$1"
Can you tell me what I'm doing wrong?

const days = 1
const result = await sql`
        select *
        from ${sql(table)}
        where
            timestamp >= current_timestamp - interval ${days} day
    `

When i use timestamp >= current_timestamp - interval '1' day all works correctly

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 with the linked Query parameters documentation and reproduce the JavaScript snippet against PostgreSQL, comparing the interpolated table and interval expressions with the working literal form. Done means determining whether this is a usage error or a client defect and documenting the correct behavior or a focused repository change.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.