Steps to reproduce
I have noticed that creating a custom enum type and a table that references it in a custom schema (other than public) causes GetSchema to fail with an exception.
To reproduce:
Create a bug schema and run the following within it:
-- Create an enum in `experiment` schema
create type bug.colors AS ENUM ('red', 'yellow', 'blue');
-- Create a table in `experiment` schema that references the enum
create table person (
name text not null,
favorite_color bug.colors not null
);
using conn = new Npgsql.NpgsqlConnection("...");
conn.Open();
// Next line will fail with "42704: type "colors" does not exist"
var columns = conn.GetSchema("Columns");
Workaround:
I can workaround the issue by also creating the enum definition in the public schema.
The issue
I think that maybe GetSchema("Columns") is making the assumption that all enums must live in public.
If you are seeing an exception, include the full exceptions details (message and stack trace).
Exception message:
42704: type "colors" does not exist
Stack trace:
at Npgsql.NpgsqlConnector.<<ReadMessage>g__ReadMessageLong|194_0>d.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
at Npgsql.NpgsqlDataReader.<Read>d__40.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Npgsql.NpgsqlDataReader.Read()
at Npgsql.NpgsqlDataAdapter.<Fill>d__27.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Npgsql.NpgsqlDataAdapter.<Fill>d__26.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Npgsql.NpgsqlDataAdapter.<Fill>d__26.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Npgsql.NpgsqlSchema.<GetColumns>d__9.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Npgsql.NpgsqlConnection.GetSchema(String collectionName, String[] restrictions)
at Npgsql.NpgsqlConnection.GetSchema(String collectionName)
at SqlHydra.Npgsql.NpgsqlSchemaProvider.getSchema(Config cfg) in C:\_github\SqlHydra\src\SqlHydra.Npgsql\NpgsqlSchemaProvider.fs:line 14
at Npgsql.Generation.lazySchema@29-2.Invoke(Unit unitVar) in C:\_github\SqlHydra\src\Tests\Npgsql\Generation.fs:line 29
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
Further technical details
Npgsql version: Reproduced in v5.0.7 and v6.0.3
PostgreSQL version:
SELECT version();
PostgreSQL 14.2 (Debian 14.2-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
Operating system:
Windows 10
Other details about my project setup:
Steps to reproduce
I have noticed that creating a custom enum type and a table that references it in a custom schema (other than public) causes
GetSchemato fail with an exception.To reproduce:
Create a
bugschema and run the following within it:Workaround:
I can workaround the issue by also creating the enum definition in the
publicschema.The issue
I think that maybe
GetSchema("Columns")is making the assumption that all enums must live inpublic.If you are seeing an exception, include the full exceptions details (message and stack trace).
Exception message:
Stack trace:
Further technical details
Npgsql version: Reproduced in v5.0.7 and v6.0.3
PostgreSQL version:
Operating system:
Windows 10
Other details about my project setup: