cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
29.9k stars 3.78k forks source link

sql: evaluation of tuple with single element #1741

Closed tbg closed 9 years ago

tbg commented 9 years ago

these currently evaluate to its only element:

// sql/parser/eval.go#EvalExpr
case Tuple:
    if len(t) == 1 {
        return EvalExpr(t[0], env)
    }

which may or may not be confusing or the wrong place to do this. There are callsites which want the element, but others want the tuple. Should figure out and decide which one it is going to be.

tbg commented 9 years ago

Unless it's by far the common case to want a DTuple{x} turn into x, I personally prefer having EvalExpr returning the expected (the one-element tuple). To avoid repeated code at the callsites, we could have a helper that does the unwrapping transparently when it applies.

petermattis commented 9 years ago

Huh, I just removed the special case for a tuple of length 1 and nothing broke. Now I'm wondering precisely why I added this in the first place. Maybe something changed in the switch from the vitess grammar to the postgres grammar. Oh well, looks like we can remove the special case and have more sanity in this code.