edgedb / edgedb

A graph-relational database with declarative schema, built-in migration system, and a next-generation query language
https://edgedb.com
Apache License 2.0
13.09k stars 402 forks source link

Named tuples with empty set fields are erroneously completely empty #5583

Closed lithdew closed 1 year ago

lithdew commented 1 year ago

Steps to Reproduce:

edgedb> select (innerIndex := <int64>{});
{}
edgedb> select <tuple<innerIndex: int64>>(innerIndex := <int64>{});
{}
edgedb> select <tuple<innerIndex: int64, test: str>>(innerIndex := <int64>{}, test := "hello");
{}
edgedb> select (<tuple<innerIndex: int64, test: str>>(innerIndex := <int64>{}, test := "hello"));
{}
edgedb> select (test := "hello");
{(test := 'hello')}
edgedb> select (test := "hello", innerIndex := <int64>{});
{}
elprans commented 1 year ago

This is expected. "Empty" in EdgeDB is not a value, and so cannot be contained in any other value. In this regard (1, <int64>{}) is not different from 1 + <int64>{}. If you have optional data, use objects instead.

lithdew commented 1 year ago

This is expected. "Empty" in EdgeDB is not a value, and so cannot be contained in any other value. In this regard (1, <int64>{}) is not different from 1 + <int64>{}. If you have optional data, use objects instead.

Would using objects require declaring the type in the schema + how would instantiating a free object instance work?

Or, is this something to be solved via. https://github.com/edgedb/rfcs/blob/master/text/1022-freetypes.rst?

elprans commented 1 year ago

Depends on whether data needs to be stored or computed ad-hoc. In the latter case you can use free shapes.

elprans commented 1 year ago

https://www.edgedb.com/docs/edgeql/select#free-objects