@@ -232,24 +232,34 @@ static async Task<DataTable> GetColumns(NpgsqlConnection conn, string?[]? restri
232232 {
233233 var columns = new DataTable ( "Columns" ) { Locale = CultureInfo . InvariantCulture } ;
234234
235- columns . Columns . AddRange ( new [ ] {
236- new DataColumn ( "table_catalog" ) , new DataColumn ( "table_schema" ) , new DataColumn ( "table_name" ) ,
237- new DataColumn ( "column_name" ) , new DataColumn ( "ordinal_position" , typeof ( int ) ) , new DataColumn ( "column_default" ) ,
238- new DataColumn ( "is_nullable" ) , new DataColumn ( "data_type" ) ,
239- new DataColumn ( "character_maximum_length" , typeof ( int ) ) , new DataColumn ( "character_octet_length" , typeof ( int ) ) ,
240- new DataColumn ( "numeric_precision" , typeof ( int ) ) , new DataColumn ( "numeric_precision_radix" , typeof ( int ) ) ,
241- new DataColumn ( "numeric_scale" , typeof ( int ) ) , new DataColumn ( "datetime_precision" , typeof ( int ) ) ,
242- new DataColumn ( "character_set_catalog" ) , new DataColumn ( "character_set_schema" ) ,
243- new DataColumn ( "character_set_name" ) , new DataColumn ( "collation_catalog" )
235+ columns . Columns . AddRange ( new DataColumn [ ] {
236+ new ( "table_catalog" ) , new ( "table_schema" ) , new ( "table_name" ) , new ( "column_name" ) ,
237+ new ( "ordinal_position" , typeof ( int ) ) ,
238+ new ( "column_default" ) ,
239+ new ( "is_nullable" ) ,
240+ new ( "data_type" ) ,
241+ new ( "character_maximum_length" , typeof ( int ) ) , new ( "character_octet_length" , typeof ( int ) ) ,
242+ new ( "numeric_precision" , typeof ( int ) ) , new ( "numeric_precision_radix" , typeof ( int ) ) , new ( "numeric_scale" , typeof ( int ) ) ,
243+ new ( "datetime_precision" , typeof ( int ) ) ,
244+ new ( "character_set_catalog" ) , new ( "character_set_schema" ) , new ( "character_set_name" ) ,
245+ new ( "collation_catalog" )
244246 } ) ;
245247
246248 var getColumns = new StringBuilder ( @"
247249SELECT
248- table_catalog, table_schema, table_name, column_name, ordinal_position, column_default, is_nullable,
249- udt_name::regtype::text AS data_type, character_maximum_length, character_octet_length, numeric_precision,
250- numeric_precision_radix, numeric_scale, datetime_precision, character_set_catalog, character_set_schema,
251- character_set_name, collation_catalog
252- FROM information_schema.columns" ) ;
250+ table_catalog, table_schema, table_name, column_name,
251+ ordinal_position,
252+ column_default,
253+ is_nullable,
254+ CASE WHEN udt_schema is NULL THEN udt_name ELSE format_type(typ.oid, NULL) END AS data_type,
255+ character_maximum_length, character_octet_length,
256+ numeric_precision, numeric_precision_radix, numeric_scale,
257+ datetime_precision,
258+ character_set_catalog, character_set_schema, character_set_name,
259+ collation_catalog
260+ FROM information_schema.columns
261+ JOIN pg_namespace AS ns ON ns.nspname = udt_schema
262+ JOIN pg_type AS typ ON typnamespace = ns.oid AND typname = udt_name" ) ;
253263
254264 using var command = BuildCommand ( conn , getColumns , restrictions , "table_catalog" , "table_schema" , "table_name" , "column_name" ) ;
255265 using var adapter = new NpgsqlDataAdapter ( command ) ;
@@ -858,4 +868,4 @@ static DataTable GetReservedWords()
858868 } ;
859869
860870 #endregion Reserved Keywords
861- }
871+ }
0 commit comments