sqlfluff / sqlfluff

A modular SQL linter and auto-formatter with support for multiple dialects and templated code.
https://www.sqlfluff.com
MIT License
7.89k stars 726 forks source link

Schema-prefixed CREATE TYPE is unparsable (DuckDB) #6225

Closed shoffmeister closed 1 month ago

shoffmeister commented 1 month ago

Search before asking

What Happened

Lint statements such as

create type myschema.mytype as int;

and get

Line 1, Position 1: Found unparsable section: 'create type myschema.mytype as int;'

Expected Behaviour

Although https://duckdb.org/docs/sql/statements/create_type.html does not explicitly show that a schema prefix is allowed, DuckDB does do it, has all the metadata for it.

On the DuckDB side I would expect a railroad diagram such as https://duckdb.org/docs/sql/statements/create_table also for types; I'll create a defect against DuckDB docs for that.

Observed Behaviour

Line 1, Position 1: Found unparsable section: 'create type myschema.mytype as int;'

How to reproduce

Given the below SQL as create-type.sql,

create schema myschema;

create type myschema.mytype as int;
create type "myschema".mytype2 as int;

create type myschema.mytype3 as myschema.mytype2;

run

sqlfluff lint --dialect duckdb create-type.sql 

The above SQL works in DuckDB 1.1.0

Dialect

duckdb

Version

sqlfluff, version 3.2.0

Configuration

none

Are you willing to work on and submit a PR to address the issue?

Code of Conduct

shoffmeister commented 1 month ago

Note that https://duckdb.org/docs/sql/statements/drop documents the availability of a "schema" for DROP TYPE myschema.mytype - which would confirm that CREATE TYPE should allow the same.

shoffmeister commented 1 month ago

FWIW, I am trying to get this to pass:

drop type if exists "myschema".mytype;
create type "myschema".mytype as int;

There may be some friction on top of just the CREATE TYPE.

shoffmeister commented 1 month ago

Created https://github.com/duckdb/duckdb-web/issues/3696 to ask for official documentation schema-prefixed types.