duckdb

Set file_search_path to environment variable


In DuckDB, is there a way to set the file_search_path using an environment variable? This would make sharing scripts among team members easier.

What I would like to be able to do is something like the following:

set file_search_path = '%userprofile%'

When I do this, DuckDB does not interpret the variable %userprofile%, it just sees it as a string.


Solution

  • Try the getenv function. On UNIX, it works as follows. It should work on Windows too with the USERPROFILE set by the OS.

    $ export USERPROFILE="test"
    $ duckdb
    
    SET file_search_path = getenv('USERPROFILE');
    SELECT current_setting('file_search_path') AS p;
    
    ┌─────────┐
    │    p    │
    │ varchar │
    ├─────────┤
    │ test    │
    └─────────┘