Skip to content

Use connection search path when attempting to lookup ambiguous type#6446

Open
ickers wants to merge 1 commit intonpgsql:mainfrom
ickers:type-by-name-lookup-use-searchpath
Open

Use connection search path when attempting to lookup ambiguous type#6446
ickers wants to merge 1 commit intonpgsql:mainfrom
ickers:type-by-name-lookup-use-searchpath

Conversation

@ickers
Copy link

@ickers ickers commented Feb 11, 2026

If an duplicate name for a type exists in multiple schemas and there is an attempt to use that name without schema-qualification then currently npgsql just throws an ArgumentException.

postgresql doesn't behave this way, instead it resolves unqualified type names based on some "search path" for the current session/user/database/connection, using the first matching type it finds in that search path.

This PR attempts to more closely align npgsql with postgresql's behaviour in this regard.

Future enhancement would be to retrieve the current search path for a connection (if not explicitly set in connection string) during initialisation instead of using hardcoded defaults as is done in this PR.

@ickers ickers requested review from roji and vonzshik as code owners February 11, 2026 04:28
@vonzshik
Copy link
Contributor

We already looked into it in #4869, and the general consensus was that it's unreliable as user can change search_path via a regular query and we have no way to react to this.

@NinoFloris
Copy link
Member

Instead we implemented https://github.com/npgsql/npgsql/blob/main/src%2FNpgsql%2FNpgsqlTypeLoadingOptions.cs#L25

This achieves much of the same if the duplicates get in the way for you.

1 similar comment
@NinoFloris
Copy link
Member

Instead we implemented https://github.com/npgsql/npgsql/blob/main/src%2FNpgsql%2FNpgsqlTypeLoadingOptions.cs#L25

This achieves much of the same if the duplicates get in the way for you.

@ickers
Copy link
Author

ickers commented Feb 13, 2026

Is it worth me pivoting this PR to just updating the exception message to make NpgsqlTypeLoadingOptions.SetTypeLoadingSchemas() feature more discoverable for subsequent users? Or shall I just close?

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.

3 participants