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

Conditional functions with constant expression as condition should evaluate only one branch #32969

Closed
vpanfilov opened this issue Dec 20, 2021 · 2 comments · Fixed by #32973
Closed
Assignees
Labels

Comments

@vpanfilov
Copy link

vpanfilov commented Dec 20, 2021

For example, if I use UInt8 constant for if condition then only one branch is evaluated:

SELECT if(1, 'success', throwIf(1, 'Executing FALSE branch'))

┌─'success'─┐
│ success   │
└───────────┘

1 rows in set. Elapsed: 0.003 sec.

But if I use some constant expression, then both branches are evaluated:

SELECT if(empty(''), 'success', throwIf(1, 'Executing FALSE branch'))

0 rows in set. Elapsed: 0.003 sec.

Received exception from server (version 21.12.2):
Code: 395. DB::Exception: Received from localhost:9000. DB::Exception: Executing FALSE branch: While processing if(empty(''), 'success', throwIf(1, 'Executing FALSE branch')). (FUNCTION_THROW_IF_VALUE_IS_NON_ZERO)
@den-crane
Copy link
Contributor

hm,

SELECT if(empty(''), 1, sleep(1));
Elapsed: 0.001 sec.

SELECT if(empty(''), 1, toDecimal64(1,2)/0);
DB::Exception: Division by zero:


SELECT if(x = '', 1, toDecimal64(1, 2) / 0)
FROM
(
    SELECT materialize('') AS x
)
DB::Exception: Division by zero:

@kitaisreal
Copy link
Collaborator

Cannot be implemented until #23194.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants