You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Expose rich PostgreSQL data type information #1276
Consumers of Npgsql sometimes need access to information on PostgreSQL data types. This is the case, for example, with the EFCore provider, which needs to know whether certain columns are of type array, as well as what their element type is.
Npgsql already has a rich representation of the backend's types internally. Expose this representation to the user via:
NpgsqlDataReader.GetColumnSchema
The upcoming ADO.NET database schema API
NpgsqlDataReader.GetPostgresType (similar to NpgsqlDataReader.GetDataTypeName)
Yes, you would be to get a new PostgresType instance that represents the data type of a column, and retrieve its associated NpgsqlDbType.
Out of curiosity, what was your scenario? When using binary copy, it's expected that you know the the data types of columns you read/write in advance...
Yeah, the COPY API requires you to know what you're doing. I actually thought about removing the option to read/write in the COPY api without explicitly specifying the NpgsqlDbType to make people think about this aspect.
But once you're code is written and works, I can see little reason to inspect column metadata in runtime and to extract the NpgsqlDbType...
BTW instead of querying with LIMIT 0 you can do ExecuteReader() with CommandBehavior.SchemaOnly.
Activity
arjennienhuis commentedon Sep 11, 2016
Would that return a NpgsqlDbType? I needed that before for better BINARY COPY support.
roji commentedon Sep 12, 2016
Yes, you would be to get a new PostgresType instance that represents the data type of a column, and retrieve its associated NpgsqlDbType.
Out of curiosity, what was your scenario? When using binary copy, it's expected that you know the the data types of columns you read/write in advance...
arjennienhuis commentedon Sep 12, 2016
It might be expected and I thought I knew the data types.
The very first copy I tried I confused a varchar(4) with an integer. No warnings, no errors just 'different' values.
Now I first do:
Then I do something silly to get the data types followed by:
roji commentedon Sep 12, 2016
Yeah, the COPY API requires you to know what you're doing. I actually thought about removing the option to read/write in the COPY api without explicitly specifying the NpgsqlDbType to make people think about this aspect.
But once you're code is written and works, I can see little reason to inspect column metadata in runtime and to extract the NpgsqlDbType...
BTW instead of querying with
LIMIT 0you can doExecuteReader()withCommandBehavior.SchemaOnly.