marcboeker / go-duckdb

go-duckdb provides a database/sql driver for the DuckDB database engine.
MIT License
679 stars 103 forks source link

Cannot pass schema and search_path as a DSN query param #176

Closed esevastyanov closed 7 months ago

esevastyanov commented 7 months ago

DSN: primary.db?schema=main or primary.db?search_path=main Code:

    connector, err := duckdb.NewConnector(DSN, func(execer driver.ExecerContext) error {
        return nil
    })

Error:

could not set config for database: affected config option schema=main

or

could not set config for database: affected config option search_path=main

Expected behaviour: no error

marcboeker commented 7 months ago

Thanks @esevastyanov for reporting this. Indeed very interesting. When listing all available config options using

count := C.duckdb_config_count()
for i := range count {
  var (
      name *C.char
      desc *C.char
  )
  state := C.duckdb_get_config_flag(i, &name, &desc)
  fmt.Println(state, i, C.GoString(name), C.GoString(desc))
}

schema and search_path are available. See the output above:

0 54 schema Sets the default search schema. Equivalent to setting search_path to a single value.
0 55 search_path Sets the default catalog search path as a comma-separated list of values

@taniabogatsch Do you have an idea, why DuckDB disallows to set the via duckdb_set_config()?

taniabogatsch commented 7 months ago

I'll try to reproduce this in C and get back to you. Feel free to assign me to this issue.

taniabogatsch commented 7 months ago

Both search_path and schema are DUCKDB_LOCAL settings, which must be set per connection. I.e., you can only set them after creating at least the duckdb instance (SET schema=main;) , i.e., via the bootQueries of the connector. duckdb_set_config can only take global settings. We'll try to improve this in the documentation. I'll also look into returning a better error message through the C API.

taniabogatsch commented 7 months ago

We can close this after merging #182. We'll improve this in our documentation and potentially have a look at the C API. But it is not a go-duckdb issue.