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

Array spread and pick infers wrong type when used as insert into ... select from (values :rows) as t #498

Open
yaziciahmet opened this issue Feb 22, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@yaziciahmet
Copy link

yaziciahmet commented Feb 22, 2023

Describe the bug
When using array spread and pick variable called rows, as follows: insert into ... select ... from (values :rows) as t (col1, col2), the types of col1 and col2 are automatically assumed to be string, even though there are number type columns in the inserted table.

Expected behavior
I would expect the type of the rows would be inferred appropriately. If this is due to postgres engine, I believe there should be a way to declare the types of the array spread and pick variables.

Test case

/*
    @name CreateIssues
    @param issues -> ((issueId!, badgeId!)...)
*/
INSERT INTO issue (id, badge_id)
SELECT tmp.issue_id, tmp.badge_id
FROM (VALUES :issues) AS tmp (issue_id, badge_id);

issue table's columns: id is TEXT, and badge_id is INT.

Here is the error I get when I try to generate ts from above query:

Error in query. Details: {
  errorCode: 'transformAssignedExpr',
  hint: 'You will need to rewrite or cast the expression.',
  message: 'column "badge_id" is of type integer but expression is of type text',
  position: '94'
}

I tried explicitly type casting as

/*
    @name CreateIssues
    @param issues -> ((issueId!, badgeId!)...)
*/
INSERT INTO issue (id, badge_id)
SELECT tmp.issue_id, tmp.badge_id::int
FROM (VALUES :issues) AS tmp (issue_id, badge_id);

Even though this removes error and successfully generates the ts, the params interface has badgeId as string.

Note: I simplified my original query as above for it to be easily readable.

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

1 participant