-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: add overloads for legitimate arithmetic operations #7414
Comments
@knz Thanks for putting this list together. Some of them I agree with, others I have reservations about:
Agreed!
I don't understand what you mean here.
This is going to require some serious restructuring, as CASE statements currently use homogenous typing rules, and I'm not sure I see where it is needed. I'm also not sure what you mean by "equality tests are are always possible between heterogeneous types", as something like
I don't think I agree. SUM on an INT column could easily overflow, which is why both Cockroach and Postgres aggregate in a larger data type. In fact, we currently mirror all (comparable) aggregate return types from https://www.postgresql.org/docs/9.5/static/functions-aggregate.html for the aggregates which we support.
But not addition and subtraction? Care to explain your reasoning?
I don't have strong feelings about this either. |
The following query:
Fails with:
So the rule I have in mind is:
Indeed. But SQL spec says, and PG supports, equality comparison between
I am willing to postpone a discussion on this until we look at the
addition/substraction between int and float is "dangerous" because I'm not very comfortable with this though so it's here merely a suggestion.
Me neither, but again I'd recommend delaying this conversation until we |
Addresses part of cockroachdb#7414. Support for this function was accidentally omitted.
Found with #7409.
The following operations provide exact results and thus should be accepted:
decimal OP int
/int OP decimal
with OP in+, -, *, /
should returndecimal
.decimal IN <tuple>
(example insqllogictest/test/random/expr/slt_good_4.test:82808
)CASE <type X> WHEN <type Y>
. SQL mandates that equality tests are always possible between heterogeneous types, so CASE/WHEN should allow this too (we can keep the type preference though).Aggregates:
SUM on type <T>
should return type<T>
. The user can always cast SUM's argument to another type to perform the sum in that type instead.Debatable:
float OP int
andint OP float
with OP in*, /
could returnfloat
decimal OP float
andfloat OP decimal
with OP in+, -, *, /
could returndecimal
The text was updated successfully, but these errors were encountered: