-
Notifications
You must be signed in to change notification settings - Fork 68
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
Allow user to configure default MotherDuck database in postgresql.conf #470
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the PR!
src/pgduckdb_duckdb.cpp
Outdated
if (duckdb_motherduck_default_database[0] == '\0') { | ||
default_dbname = db_manager.GetDefaultDatabase(context); | ||
} else { | ||
default_dbname = duckdb_motherduck_default_database; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of overriding the default database that motherduck sets, let's instead make motherduck set the correct default database by providing the database in the connection string:
connection_string = psprintf("md:%s?motherduck_token=%s", duckdb_motherduck_default_database, duckdb_motherduck_token);
For that you need to escape the database name though using URI escaping. I think the following function should work for that:
char *
uri_escape(const char *input)
{
StringInfoData buf;
initStringInfo(&buf);
while (*str)
{
char c = *str++;
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '_' || c == '.' || c == '~')
{
appendStringInfoChar(&buf, c);
}
else
{
appendStringInfo(&buf, "%%%02X", (unsigned char)c);
}
}
return buf.data;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tip! I didn't realize you could just stick the db name in the connection string, clean solution.
Is it ok that I just stuck the uri_escape function in the same file?
619aef4
to
c13448d
Compare
c13448d
to
8c2d0f2
Compare
Thanks a lot for your work on this. I played a bit with your changes and realized that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
0812a06
to
e7643a6
Compare
Fixes #459
Allow the user to configure a different default MotherDuck database from
my_db
inpostgresql.conf
. This affords flexibility because there is currently no user-facing API to change the internal "default" DB in MotherDuck.