@@ -52,13 +52,15 @@ public DataTypeName(string fullyQualifiedDataTypeName)
5252 internal static DataTypeName ValidatedName ( string fullyQualifiedDataTypeName )
5353 => new ( fullyQualifiedDataTypeName , validated : true ) ;
5454
55+ bool IsUnqualifiedDisplayName => SchemaSpan is "pg_catalog" || IsUnqualified ;
56+
5557 // Includes schema unless it's pg_catalog or the schema is an invalid character used to represent an unspecified schema.
5658 public string DisplayName =>
57- Value . StartsWith ( "pg_catalog" , StringComparison . Ordinal ) || IsUnqualified
59+ IsUnqualifiedDisplayName
5860 ? UnqualifiedDisplayName
5961 : Schema + "." + UnqualifiedDisplayName ;
6062
61- public string UnqualifiedDisplayName => ToDisplayName ( UnqualifiedNameSpan ) ;
63+ public string UnqualifiedDisplayName => ToDisplayName ( UnqualifiedNameSpan , mapAliases : IsUnqualifiedDisplayName ) ;
6264
6365 internal ReadOnlySpan < char > SchemaSpan => Value . AsSpan ( 0 , _value . IndexOf ( '.' ) ) ;
6466 public string Schema => Value . Substring ( 0 , _value . IndexOf ( '.' ) ) ;
@@ -124,27 +126,20 @@ public DataTypeName ToDefaultMultirangeName()
124126
125127 // Create a DataTypeName from a broader range of valid names.
126128 // including SQL aliases like 'timestamp without time zone', trailing facet info etc.
127- public static DataTypeName FromDisplayName ( string displayName , string ? schema = null )
128- => FromDisplayName ( displayName , schema , assumeUnqualified : false ) ; // user strings may come fully qualified.
129-
130- // This method is used during type loading, it allows us to accept friendly names in constructors, without having to preconcatenate the schema.
131- internal static DataTypeName FromDisplayName ( string displayName , string ? schema , bool assumeUnqualified )
129+ public static DataTypeName FromDisplayName ( string displayName )
132130 {
133131 var displayNameSpan = displayName . AsSpan ( ) . Trim ( ) ;
134132
135133 var schemaEndIndex = displayNameSpan . IndexOf ( '.' ) ;
136134 ReadOnlySpan < char > schemaSpan ;
137- if ( schemaEndIndex is not - 1 && ! assumeUnqualified )
135+ if ( schemaEndIndex is not - 1 )
138136 {
139- if ( schema is not null )
140- throw new ArgumentException ( "Schema provided for a fully qualified name." ) ;
141-
142137 schemaSpan = displayNameSpan . Slice ( 0 , schemaEndIndex ) ;
143138 displayNameSpan = displayNameSpan . Slice ( schemaEndIndex + 1 ) ;
144139 }
145140 else
146141 {
147- schemaSpan = schema is null ? $ "{ InvalidIdentifier } " : schema . AsSpan ( ) ;
142+ schemaSpan = $ "{ InvalidIdentifier } ";
148143 }
149144
150145 // Then we strip either of the two valid array representations to get the base type name (with or without facets).
@@ -196,7 +191,7 @@ internal static DataTypeName FromDisplayName(string displayName, string? schema,
196191 var value => value
197192 } ;
198193
199- if ( schema is null && DataTypeNames . IsWellKnownUnqualifiedName ( mapped ) )
194+ if ( DataTypeNames . IsWellKnownUnqualifiedName ( mapped ) )
200195 schemaSpan = "pg_catalog" . AsSpan ( ) ;
201196
202197 return new ( string . Concat ( schemaSpan , "." , isArray ? "_" : "" , mapped ) ) ;
@@ -207,29 +202,33 @@ internal static DataTypeName FromDisplayName(string displayName, string? schema,
207202 // Additionally array types have a '_' prefix while for readability their element type should be postfixed with '[]'.
208203 // See the table for all the aliases https://www.postgresql.org/docs/current/static/datatype.html#DATATYPE-TABLE
209204 // Alternatively some of the source lives at https://github.com/postgres/postgres/blob/c8e1ba736b2b9e8c98d37a5b77c4ed31baf94147/src/backend/utils/adt/format_type.c#L186
210- static string ToDisplayName ( ReadOnlySpan < char > unqualifiedName )
205+ static string ToDisplayName ( ReadOnlySpan < char > unqualifiedName , bool mapAliases )
211206 {
212207 var isArray = unqualifiedName . IndexOf ( '_' ) is 0 ;
213208 var baseTypeName = isArray ? unqualifiedName . Slice ( 1 ) : unqualifiedName ;
214209
215- var mappedBaseType = baseTypeName switch
210+ string ? mappedBaseType = null ;
211+ if ( mapAliases )
216212 {
217- "bool" => "boolean" ,
218- "bpchar" => "character" ,
219- "decimal" => "numeric" ,
220- "float4" => "real" ,
221- "float8" => "double precision" ,
222- "int2" => "smallint" ,
223- "int4" => "integer" ,
224- "int8" => "bigint" ,
225- "time" => "time without time zone" ,
226- "timestamp" => "timestamp without time zone" ,
227- "timetz" => "time with time zone" ,
228- "timestamptz" => "timestamp with time zone" ,
229- "varbit" => "bit varying" ,
230- "varchar" => "character varying" ,
231- _ => null
232- } ;
213+ mappedBaseType = baseTypeName switch
214+ {
215+ "bool" => "boolean" ,
216+ "bpchar" => "character" ,
217+ "decimal" => "numeric" ,
218+ "float4" => "real" ,
219+ "float8" => "double precision" ,
220+ "int2" => "smallint" ,
221+ "int4" => "integer" ,
222+ "int8" => "bigint" ,
223+ "time" => "time without time zone" ,
224+ "timestamp" => "timestamp without time zone" ,
225+ "timetz" => "time with time zone" ,
226+ "timestamptz" => "timestamp with time zone" ,
227+ "varbit" => "bit varying" ,
228+ "varchar" => "character varying" ,
229+ _ => null
230+ } ;
231+ }
233232
234233 return isArray
235234 ? string . Concat ( mappedBaseType ?? baseTypeName , "[]" )
0 commit comments