Skip to content

Composite types in more than one schema #4365

@davidhunt135

Description

@davidhunt135

Hi,

I've come across a problem which I haven't been able to solve without modification to the npgsql code and was wondering whether there is either a better solution or if it would be considered a bug and I could create a PR.

I have a multi tenant database managed by having one schema per tenant. For each of these tenants there are a matching set of composite types. This schema will be different for each connection to the DB. If I register the clr type for each with a name then try to execute a routine which returns one of those types I get the following error:

More than one PostgreSQL type was found with the name ... please specify a full name including schema: ...

I assumed that a solution would be to call MapComposite for each connection defining the schema (tenant) in the name or with an instance of INpgsqlNameTranslator which would prefix the schema on the type name. Neither of these approaches worked as I thought it would, I still got the same error. The problem appears to be that when ConnectorTypeMapper looks for the type it uses PostgresType.Name which does not include the schema defined on the type thus resulting in multiple types being found.

I have found that I can get this working by updating ConnectortypeMapper line 87 to use pgType.DisplayName instead of pgType.Name but that would require forking and maintaining or having a PR accepted for the change.

Is there another approach to resolve this issue without a change to npgsql? Unfortunately I can't change the db tenancy model.

I have tried with NpgSql version 6.0.1 and 6.0.3.

Thanks

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions