dolthub / dolt

Dolt – Git for Data
Apache License 2.0
17.58k stars 498 forks source link

Dolt does not support CREATE TABLE ... AS ... with a table definition #7996

Open arvidfm opened 2 months ago

arvidfm commented 2 months ago

The following works in MySQL to create a table with a specific schema while initialising it with data at the same time:

CREATE TEMPORARY TABLE tmp_test (
    `id` INT PRIMARY KEY
)
AS SELECT 1 `id`;

With Dolt, however, this results in a syntax error at position 64 near 'AS'.

It's trivial to work around by splitting it into separate CREATE TABLE and INSERT INTO statements, but you do lose some atomicity which would be nice to have in migrations.

Note that with MySQL, it seems you need to give the columns in the SELECT query explicit names in order to map them to the correct columns in the table.