dolthub / dolt

Dolt – Git for Data
Apache License 2.0
17.82k stars 504 forks source link

VALUES statement not supported #8012

Closed arvidfm closed 3 months ago

arvidfm commented 3 months ago

MySQL allows for using VALUES ROW(...), ROW(...), ...; as a standalone statement for generating a multi-row table, where the columns will have the names column_0, column_1, etc:

> VALUES ROW(1, 2, 3), ROW(4, 5, 6);
+----------+----------+----------+
| column_0 | column_1 | column_2 |
+----------+----------+----------+
|        1 |        2 |        3 |
|        4 |        5 |        6 |
+----------+----------+----------+
2 rows in set (0.01 sec)

This is not currently available in Dolt:

> VALUES ROW(1, 2, 3), ROW(4, 5, 6);
Error parsing SQL: 
syntax error at position 7 near 'VALUES'
VALUES ROW(1, 2, 3), ROW(4, 5, 6)

However, Dolt does support the syntax in subqueries, e.g. as a table reference in a JOIN statement, and it's unclear how much value the ability to use it as a standalone statement would bring.

If you really need to generate a table using inline data with no further processing, a simple workaround is to use it as a subquery in a SELECT statement:

> SELECT * FROM (VALUES ROW(1, 2, 3), ROW(4, 5, 6)) t;
+----------+----------+----------+
| column_0 | column_1 | column_2 |
+----------+----------+----------+
| 1        | 2        | 3        |
| 4        | 5        | 6        |
+----------+----------+----------+
2 rows in set (0.00 sec)
jycor commented 3 months ago

Hey @arvidfm, fix for this is making its way to dolt main.

We support the syntax listed in this issue, but we are missing the case for SELECT (VALUES ...). Additionally, our VALUES constructor is more lenient than MySQL's (part of having some compatibility with PostgreSQL), so the ROW is not required. For example:

tmp/main*> values (1, 2, 3), (4, 5, 6);
+----------+----------+----------+
| column_0 | column_1 | column_2 |
+----------+----------+----------+
| 1        | 2        | 3        |
| 4        | 5        | 6        |
+----------+----------+----------+
2 rows in set (0.00 sec)

Expect a release later today.