menu

EdgeDB

Bringing state-of-the-art database technology to the masses.

Channels
Team

Interesting "wat" discovery...

February 24, 2020 at 3:47am

Interesting "wat" discovery...

February 24, 2020 at 3:47am
It seems the compiler for DDL functions gets confused about the type of something if you try to return a UNION. On the one hand, the return type will be type you enforced with annotations and practical sense, but on the other hand... it's not. It's also an int64. How would I shield myself from this behavior exactly. Explicit type casting is just not enough.

February 24, 2020 at 4:07am
Can you give an example?
  • reply
  • like

February 25, 2020 at 6:38pm
It's also an int64
When performing a UNION on scalars the resulting set has to be of a homogeneous type, so that means that if you do 3.2 UNION 4 (a float64 and an int64), the resulting set will be {3.2, 4.0} of type float64 as that is the more general of the two. Basically mixing ints and floats will generally upcast everything to float. So if you want to control the types more strictly, consider explicit casts of the elements before you put them in a UNION or an explicit cast of the entire result.
Edited
  • reply
  • like

February 28, 2020 at 12:26am
Sure thing, and I see where you're coming from, but Elvis helped me construct this on a GitHub issue.
CREATE FUNCTION api::DefaultGuestSession() -> SET OF api::Session
USING EdgeQL $$
FOR GUEST IN {api::select_guest_user()}
UNION (
INSERT api::Session {
sessionID := (SELECT api::random_str_id()),
user := GUEST
}
)
$$;
actually enforces the return signature to be added (and to be correct, so I was advised by the interpreter to addapi::Session. But the unexpected part is that when I use the explicit type-annotation on the SELECT that calls DefaultGuestSession, the cli yells at me for comparing a <api::Session>{ } an int64. It begs the question - what exactly is the union of an insert? Logically, it would have to the set of a single element whose type is returned by the INSERT function, so is it a raw pointer? an ID?
Edited
  • reply
  • like
INSERT returns the type of the inserted object. How does your function call site look like?
  • reply
  • like

February 28, 2020 at 8:55pm
This is really weird. It's not happening anymore and I can't recreate the error, but I swear I am telling the truth. Sorry guys, the next time it happens, I'll add it to this thread.
  • reply
  • like