ormin icon indicating copy to clipboard operation
ormin copied to clipboard

query doesn't infer single row from selecting unique items

Open alaviss opened this issue 5 years ago • 4 comments

Given a schema like this:

create table user(
  id integer primary key,
  username text unique
)

I'd expect that

let (id, username) =
  query:
    select user(id, username)
    where id == 1

or

let (id, username) =
  query:
    select user(id, username)
    where username == "alaviss"

Would work without limit 1.

The error message is also confusing:

test.nim(6, 5) Error: 'tuple' expected

Took me a moment to realize that it was trying to return a seq.

alaviss avatar Feb 27 '20 19:02 alaviss

You need limit 1, otherwise it will return a seq.

huaxk avatar Feb 28 '20 01:02 huaxk

You need limit 1, otherwise it will return a seq.

I know. The idea is that this should not be needed, as we can clearly see from the schema that there can only be at most one element from this kind of matching.

alaviss avatar Feb 28 '20 03:02 alaviss

Ormin maybe not so smart!

huaxk avatar Feb 28 '20 13:02 huaxk

Since Ormin will never be "smart" (it's just software), easier and more predictable rules don't hurt. The limit 1 is fine. However, if you disagree and are willing to implement it, ignore me.

Araq avatar Mar 03 '20 12:03 Araq