sql-formatter icon indicating copy to clipboard operation
sql-formatter copied to clipboard

Feature Request: Support for Duckdb

Open PMassicotte opened this issue 1 year ago • 4 comments

duckdb is getting a lot of attention as a fast in-process analytical database. I found out that duckdb is not currently supported. I am currently using spark option, but it is not working every time.

Are there any plans to add it?

PMassicotte avatar Apr 12 '24 13:04 PMassicotte

Thanks for the feature request.

I'm open for a pull request, but I'm not really interested in implementing it by myself. Luckily for you, adding a support for a new dialect to sql-formatter is not that hard. You don't even need to fork sql-formatter to do so, you can just provide it a custom dialect definition.

Well, admittedly there's not that much of documentation there, but just copying an existing dialect implementation from sql-formatter source code and modifying it slightly should be pretty simple.

You can also look at the wiki, which documents syntax details of all the currently supported SQL dialects.

nene avatar Apr 13 '24 06:04 nene

Great, I will have a look at it!

PMassicotte avatar Apr 13 '24 07:04 PMassicotte

Just for reference:

select * from duckdb_keywords();
select * from duckdb_functions();

PMassicotte avatar Apr 13 '24 10:04 PMassicotte

I've set up a PR for this.

It's based on the duckdb words:

COPY (
    SELECT DISTINCT upper(function_name) AS function_name
    FROM duckdb_functions()
    WHERE function_name SIMILAR TO '^[a-z].*'
    ORDER BY function_name
) TO 'duckdb_functions.txt' WITH (sep ',', header FALSE);


COPY (
    SELECT upper(keyword_name)
    FROM duckdb_keywords()
    ORDER BY keyword_name
) TO 'duckdb_keywords.txt' WITH (sep ',', header FALSE);


COPY (
    SELECT DISTINCT upper(logical_type)
    FROM duckdb_types()
    ORDER BY logical_type
) TO 'duckdb_types.txt' WITH (sep ',', header FALSE);

I've also leveraged the postgres tests, most are passing. I'm not clear on how to resolve the failing tests - it would be great to get some help.

hughcameron avatar Apr 30 '24 07:04 hughcameron

DuckDB is now supported in 15.6.0.

nene avatar Apr 20 '25 18:04 nene