fix: current_database() returns the configured catalog name, not the literal "datafusion"#375
Merged
sunng87 merged 1 commit intoJul 16, 2026
Conversation
…literal "datafusion" create_current_database_udf hardcoded "datafusion" regardless of the catalog the session was set up with. setup_pg_catalog already has the catalog name in scope; thread it through so SELECT current_database() reflects the database the client connected to, per PostgreSQL semantics. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
create_current_database_udf()registers acurrent_database()UDF that returns the hardcoded literal"datafusion", regardless of the catalog the session was actually set up with:But
setup_pg_catalog(session_context, catalog_name, ...)already knows the real catalog name — it registerspg_catalogunder exactly that name a few lines above. So a client that connects to catalogmydband runsSELECT current_database()gets"datafusion"instead of"mydb".In PostgreSQL,
current_database()reflects the database the client connected to and is fixed for the life of the connection. Tools that key off it — psql's\conninfo/ prompt substitution, some ORMs and schema-migration tools that route bycurrent_database(),pg_table_is_visible()-style visibility helpers — misbehave against the hardcoded value.Fix
Thread the catalog name that
setup_pg_catalogalready has in scope into the UDF, and return it verbatim:and at the call site:
No new plumbing —
catalog_nameis already a parameter ofsetup_pg_catalog.Compatibility note
create_current_database_udfispub, so adding the&strparameter is a breaking signature change for anyone calling it directly (the in-repo call site is the only caller in this workspace, and it's updated here). If you'd prefer to preserve the old zero-arg signature, I'm happy to instead add a secondcreate_current_database_udf_for(name: &str)and keep the old one as a thin wrapper — just let me know which you'd rather carry.Test
Added a regression test in
datafusion-pg-catalog'spg_catalogtest module: set up the catalog under"my_database", runSELECT current_database(), and assert it returns"my_database"(not"datafusion").Context
Found while building a multi-catalog pg-wire frontend on top of
datafusion-pg-catalog, where each connection maps to a distinct catalog andcurrent_database()needs to reflect it.🤖 Generated with Claude Code