You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is something anticipated by the type system and something that will be useful for expanding our std module (for example for #2125).
At the moment this is not easily implementable, as our backend does not have capabilities for checking a type at runtime. I also don't have a plan for how will this be implemented.
I do know that enums should not be just enumerations of values, but a named union - a proper sum-type:
But can this still be used together with filter to filter integers or strings?
Maybe the column InvoiceKind contains integers such as 1, 2, 3, or a string such as "PAID" or "UNPAID".
I can't remember what those integers mean so I want to look them via enum.
I didn't talk about it above, but the "discriminator" between the enum values (i.e. the thing that is actually written into the table) should be configurable, as you propose.
This is because there are already databases that contain enums based on strings, ints and actual enum types and we want to be able to write idiomatic queries for all of them.
Activity
[-]Add enums[/-][+]Enums[/+][-]Enums[/-][+]Enums / named unions[/+]aljazerzen commentedon Dec 18, 2023
This is something anticipated by the type system and something that will be useful for expanding our std module (for example for #2125).
At the moment this is not easily implementable, as our backend does not have capabilities for checking a type at runtime. I also don't have a plan for how will this be implemented.
I do know that enums should not be just enumerations of values, but a named union - a proper sum-type:
(I'm using made-up syntax that is most consistent with the rules for other type-system constructs.)
Related resource: https://www.parsonsmatt.org/2019/03/19/sum_types_in_sql.html
vanillajonathan commentedon Dec 18, 2023
But can this still be used together with
filterto filter integers or strings?Maybe the column
InvoiceKindcontains integers such as1,2,3, or a string such as"PAID"or"UNPAID".I can't remember what those integers mean so I want to look them via enum.
aljazerzen commentedon Dec 19, 2023
Yes it could be used in
filter. I'm thinking about pattern matching very similar to Rust's:I didn't talk about it above, but the "discriminator" between the enum values (i.e. the thing that is actually written into the table) should be configurable, as you propose.
This is because there are already databases that contain enums based on strings, ints and actual enum types and we want to be able to write idiomatic queries for all of them.
vanillajonathan commentedon Dec 19, 2023
Looks powerful, but also quite verbose. I would still like to be able to do simple stuff such as: