Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect pg format #18

Open
konsumer opened this issue Aug 23, 2023 · 0 comments
Open

Incorrect pg format #18

konsumer opened this issue Aug 23, 2023 · 0 comments

Comments

@konsumer
Copy link

konsumer commented Aug 23, 2023

The library works otherwise, but this makes invalid SQL:

import format from 'sqlutils/pg/format.js'

const records = [
  {
    run: '1692826907-allwords',
    platform: 'APPLE',
    locale: 'en-US',
    term: 'electricity',
    rank: 10,
    total: 10,
    score: 4,
    result: 'electricity bill calculator $',
    ip: '127.0.0.1',
    pass: 1
  }
]

// copy to show that records is being modified in-place
const original = JSON.parse(JSON.stringify(records))

const query = format('INSERT INTO results ?', records)

console.log(JSON.stringify({ query, original, records }, null, 2))

Looks like it doesn't like the $, which is valid for duckdb (which uses postgres sql syntax)
Additionally, it appears to be modifying my input, in-place, which is very bad.

{
  "query": "INSERT INTO results (run,platform,locale,term,rank,total,score,result,ip,pass) VALUES ('1692826907-allwords','APPLE','en-US','electricity',10,10,4,'electricity bill calculator ,'127.0.0.1',1)",
  "original": [
    {
      "run": "1692826907-allwords",
      "platform": "APPLE",
      "locale": "en-US",
      "term": "electricity",
      "rank": 10,
      "total": 10,
      "score": 4,
      "result": "electricity bill calculator $",
      "ip": "127.0.0.1",
      "pass": 1
    }
  ],
  "records": [
    {
      "run": "'1692826907-allwords'",
      "platform": "'APPLE'",
      "locale": "'en-US'",
      "term": "'electricity'",
      "rank": "10",
      "total": "10",
      "score": "4",
      "result": "'electricity bill calculator $'",
      "ip": "'127.0.0.1'",
      "pass": "1"
    }
  ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant