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

[BUG]: Using values([]) in a query creates invalid syntax #441

Closed
tmcw opened this issue Apr 12, 2023 · 3 comments
Closed

[BUG]: Using values([]) in a query creates invalid syntax #441

tmcw opened this issue Apr 12, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@tmcw
Copy link
Contributor

tmcw commented Apr 12, 2023

What version of drizzle-orm are you using?

0.23.10

Describe the Bug

Given this query:

      console.log(
        db
          .insert(table)
          .values([])
          .onConflictDoNothing({
            target: [table.id],
          })
          .toSQL()
      );

values([]) generates "", which generates SQL like

insert into "table" ("id") values  on conflict ("parentValNameId","refValNameId") do nothing

Which is invalid. Unfortunately TS is limited in saying that a type must be a "non-empty array" but maybe postgres will accept () as values?

@tmcw tmcw added the bug Something isn't working label Apr 12, 2023
@izakfilmalter
Copy link
Contributor

Would be great for the query to not fire. Ran into the same thing. I guess the best course of action is to convert to an NEA and conditionally fire the insert.

@migueloller
Copy link

Related to #464

@dankochetov dankochetov self-assigned this Apr 19, 2023
@dankochetov
Copy link
Contributor

This should be checked upstream, since there's not much the ORM can do here. I'll add a verbose error for this case, but that's about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants