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

type inference for ValArg doesn't work for some expressions: CASE, function application #4024

Closed
andreimatei opened this issue Jan 28, 2016 · 4 comments
Assignees

Comments

@andreimatei
Copy link
Contributor

No description provided.

@andreimatei andreimatei self-assigned this Jan 28, 2016
@andreimatei andreimatei changed the title type inference doesn't work for some expressions: CASE, function application type inference for ValArg doesn't work for some expressions: CASE, function application Jan 28, 2016
@petermattis
Copy link
Collaborator

Can you provide some concrete examples? I recall there are difficulties in doing type inference for CASE expressions, though not the details.

@JackKrupansky
Copy link

A function with a single argument which is a ValArg. Normally type check would infer the type of the ValArg from other, non-ValArg function arguments. Or, a function where all arguments are ValArgs.

@vivekmenezes
Copy link
Contributor

In the bank example while using the pgwire protocol the following doesn't work:

from := rand.Intn(*numAccounts)
to := rand.Intn(*numAccounts - 1)
if from == to {
    to = *numAccounts - 1
}
amount := rand.Intn(*maxTransfer)

update := `                                                                           
    UPDATE bank.accounts                                                                            
    SET balance = CASE id WHEN $1 THEN balance-$3 WHEN $2 THEN balance+$3 END
    WHERE id IN ($1, $2) AND (SELECT balance >= $3 FROM bank.accounts WHERE id = $1)`
if _, err := clients[i].db.Exec(update, from, to, amount); err != nil {
    return err
}

I see the error

incompatible condition types int, valarg

Looking into the code this appears to be the type checker while evaluating the WHEN clause.

@maddyblue
Copy link
Contributor

The fix I have for this only fixes CASE statements. Please make single issues for the other kinds of statements with examples for which prepare fails.

@vivekmenezes the bank example is now closer to working. Subqueries are failing with prepare. Working on that now.

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

5 participants