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

Typegen fails on unnest #413

Open
tbillington opened this issue Sep 29, 2022 · 1 comment
Open

Typegen fails on unnest #413

tbillington opened this issue Sep 29, 2022 · 1 comment

Comments

@tbillington
Copy link

Typegen fails on call with unnest. The output is Query is not typeable.

I would expect that in this case the types in the where clause should not matter to the typegen, since the columns are pulled straight from a table, not based on anything to do with the unpacked rows.

When I remove the where clause, the query typegens successfully.

slonik

const pairs: [string, string][] = ...;
sql`
select
  col_a,
  col_b,
  col_c
from
  data_table
where
  (col_a, col_b)
  = ANY(select col_a, col_b from ${sql.unnest(pairs, [
    'text',
    'text',
  ])})
`

generated sql

select
    col_a,
    col_b,
    col_c
from
    data_table
where
    (col_a, col_b)
    = ANY(select col_a, col_b from unnest($1::"text"[], $2::"text"[]))
@mmkal
Copy link
Owner

mmkal commented Dec 6, 2023

There's some logic that (tries to) convert all wheres into where true since where doesn't make a difference to the output type. But clearly it's tripping up on where clauses with complex values (even if they're not relevant).

I'll look into fixing that logic, but I also would like to add some kind of -- typegen-ignore-next-line directive which basically tells the tool to act as though the following line doesn't exist. That might be a workable escape hatch for this kind of thing too.

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

2 participants