Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add duckdb_functions table function #2729

Merged
merged 4 commits into from
Dec 6, 2021

Conversation

Mytherin
Copy link
Collaborator

@Mytherin Mytherin commented Dec 3, 2021

This PR adds the duckdb_functions table function, that shows the list of functions currently built into the system, e.g.:

D select distinct on(function_name) function_name, function_type, return_type, parameters, parameter_types from duckdb_functions() where function_type='scalar' limit 10;
┌────────────────┬───────────────┬─────────────┬──────────────────────────┬──────────────────────────────────────┐
│ function_name  │ function_type │ return_type │        parameters        │           parameter_types            │
├────────────────┼───────────────┼─────────────┼──────────────────────────┼──────────────────────────────────────┤
│ log10          │ scalar        │ DOUBLE      │ [col0]                   │ [DOUBLE]                             │
│ mod            │ scalar        │ TINYINT     │ [col0, col1]             │ [TINYINT, TINYINT]                   │
│ date_diff      │ scalar        │ BIGINT      │ [col0, col1, col2]       │ [VARCHAR, DATE, DATE]                │
│ writefile      │ scalar        │ VARCHAR     │ []                       │ []                                   │
│ regexp_replace │ scalar        │ VARCHAR     │ [col0, col1, col2, col3] │ [VARCHAR, VARCHAR, VARCHAR, VARCHAR] │
│ age            │ scalar        │ INTERVAL    │ [col0]                   │ [TIMESTAMP]                          │
│ age            │ scalar        │ INTERVAL    │ [col0, col1]             │ [TIMESTAMP, TIMESTAMP]               │
│ datediff       │ scalar        │ BIGINT      │ [col0, col1, col2]       │ [VARCHAR, DATE, DATE]                │
│ map            │ scalar        │ MAP         │ []                       │ []                                   │
│ year           │ scalar        │ BIGINT      │ [col0]                   │ [TIMESTAMP WITH TIME ZONE]           │
└────────────────┴───────────────┴─────────────┴──────────────────────────┴──────────────────────────────────────┘

D select distinct on(function_type) * from duckdb_functions();
┌─────────────┬─────────────────────┬───────────────┬─────────────┬─────────────┬────────────────────┬─────────────────┬─────────┬────────────────────┐
│ schema_name │    function_name    │ function_type │ description │ return_type │     parameters     │ parameter_types │ varargs │  macro_definition  │
├─────────────┼─────────────────────┼───────────────┼─────────────┼─────────────┼────────────────────┼─────────────────┼─────────┼────────────────────┤
│ main        │ parquet_schema      │ table         │ NULLNULL        │ [col0]             │ [VARCHAR]       │ NULLNULL               │
│ main        │ log10               │ scalar        │ NULL        │ DOUBLE      │ [col0]             │ [DOUBLE]        │ NULLNULL               │
│ main        │ count_star          │ aggregate     │ NULLBIGINT      │ []                 │ []              │ NULLNULL               │
│ main        │ table_info          │ pragma        │ NULLNULL        │ [col0]             │ [VARCHAR]       │ NULLNULL               │
│ pg_catalog  │ has_table_privilege │ macro         │ NULLNULL        │ [table, privilege] │ [NULL, NULL]    │ NULL    │ CAST(t AS BOOLEAN) │
└─────────────┴─────────────────────┴───────────────┴─────────────┴─────────────┴────────────────────┴─────────────────┴─────────┴────────────────────┘

Currently the description and parameter names of functions are still missing. The idea is to add those to the system in a later refactor of the system.

The purpose of this function is to help with auto-generating of documentation (CC @Alex-Monahan) and to add support for displaying available functions of the system (e.g. using SHOW FUNCTIONS or similar).

@Alex-Monahan
Copy link
Contributor

This will also be great for adding autocomplete to an IDE using DuckDB! Thanks Mark!

@mskyttner
Copy link

Could it be useful also for tab completion in the duckdb CLI? https://sqlite.org/completion.html mentions tab completion for keywords, and schema, table, and column names but mentions plans for adding also completions taken from function and pragma names.

And maybe for autocompletion in the duckdb_rest_server frontend? https://github.com/duckdb/duckdb/tree/master/tools/rest/frontend

@Mytherin
Copy link
Collaborator Author

Mytherin commented Dec 6, 2021

Could it be useful also for tab completion in the duckdb CLI? https://sqlite.org/completion.html mentions tab completion for keywords, and schema, table, and column names but mentions plans for adding also completions taken from function and pragma names.

And maybe for autocompletion in the duckdb_rest_server frontend? https://github.com/duckdb/duckdb/tree/master/tools/rest/frontend

Yes, this would surely be useful for that.

@Mytherin Mytherin merged commit 5dec413 into duckdb:master Dec 6, 2021
@rsund
Copy link
Contributor

rsund commented Jan 10, 2022

COALESCE seems to be missing from the duckdb_functions() table. It is, however, listed in the duckdb_keywords() table.

@Mytherin Mytherin deleted the duckdb_functions branch June 21, 2022 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants