@@ -391,8 +391,8 @@ pub fn plan_insert_query(
391391 sql_err ! (
392392 "column {} is of type {} but expression is of type {}" ,
393393 desc. get_name( ordering[ e. column] ) . as_str( ) . quoted( ) ,
394- qcx. humanize_scalar_type( & e. target_type) ,
395- qcx. humanize_scalar_type( & e. source_type) ,
394+ qcx. humanize_scalar_type( & e. target_type, false ) ,
395+ qcx. humanize_scalar_type( & e. source_type, false ) ,
396396 )
397397 } ) ?;
398398
@@ -1255,8 +1255,8 @@ pub fn plan_params<'a>(
12551255 if st != * ty {
12561256 sql_bail ! (
12571257 "mismatched parameter type: expected {}, got {}" ,
1258- ecx. humanize_scalar_type( ty) ,
1259- ecx. humanize_scalar_type( & st) ,
1258+ ecx. humanize_scalar_type( ty, false ) ,
1259+ ecx. humanize_scalar_type( & st, false ) ,
12601260 ) ;
12611261 }
12621262 let ex = ex. lower_uncorrelated ( ) ?;
@@ -1602,12 +1602,12 @@ pub fn plan_ctes(
16021602 let proposed_typ = proposed_typ
16031603 . column_types
16041604 . iter ( )
1605- . map ( |ty| qcx. humanize_scalar_type ( & ty. scalar_type ) )
1605+ . map ( |ty| qcx. humanize_scalar_type ( & ty. scalar_type , false ) )
16061606 . collect :: < Vec < _ > > ( ) ;
16071607 let inferred_typ = derived_typ
16081608 . column_types
16091609 . iter ( )
1610- . map ( |ty| qcx. humanize_scalar_type ( & ty. scalar_type ) )
1610+ . map ( |ty| qcx. humanize_scalar_type ( & ty. scalar_type , false ) )
16111611 . collect :: < Vec < _ > > ( ) ;
16121612 Err ( PlanError :: RecursiveTypeMismatch (
16131613 cte_name,
@@ -1620,7 +1620,7 @@ pub fn plan_ctes(
16201620 return type_err ( proposed_typ, derived_typ) ;
16211621 }
16221622
1623- // Cast dervied types to proposed types or error.
1623+ // Cast derived types to proposed types or error.
16241624 let val = match cast_relation (
16251625 qcx,
16261626 // Choose `CastContext::Assignment`` because the user has
@@ -1753,8 +1753,8 @@ fn plan_set_expr(
17531753 Err ( _) => sql_bail ! (
17541754 "{} types {} and {} cannot be matched" ,
17551755 op,
1756- qcx. humanize_scalar_type( & left_type. scalar_type) ,
1757- qcx. humanize_scalar_type( & target) ,
1756+ qcx. humanize_scalar_type( & left_type. scalar_type, false ) ,
1757+ qcx. humanize_scalar_type( & target, false ) ,
17581758 ) ,
17591759 }
17601760 match typeconv:: plan_cast (
@@ -1767,8 +1767,8 @@ fn plan_set_expr(
17671767 Err ( _) => sql_bail ! (
17681768 "{} types {} and {} cannot be matched" ,
17691769 op,
1770- qcx. humanize_scalar_type( & target) ,
1771- qcx. humanize_scalar_type( & right_type. scalar_type) ,
1770+ qcx. humanize_scalar_type( & target, false ) ,
1771+ qcx. humanize_scalar_type( & right_type. scalar_type, false ) ,
17721772 ) ,
17731773 }
17741774 }
@@ -2034,8 +2034,8 @@ fn plan_values_insert(
20342034 Err ( _) => sql_bail ! (
20352035 "column {} is of type {} but expression is of type {}" ,
20362036 target_names[ column] . as_str( ) . quoted( ) ,
2037- qcx. humanize_scalar_type( target_type) ,
2038- qcx. humanize_scalar_type( source_type) ,
2037+ qcx. humanize_scalar_type( target_type, false ) ,
2038+ qcx. humanize_scalar_type( source_type, false ) ,
20392039 ) ,
20402040 } ;
20412041 if column >= types. len ( ) {
@@ -3418,7 +3418,10 @@ fn expand_select_item<'a>(
34183418 let expr = plan_expr ( ecx, sql_expr) ?. type_as_any ( ecx) ?;
34193419 let fields = match ecx. scalar_type ( & expr) {
34203420 ScalarType :: Record { fields, .. } => fields,
3421- ty => sql_bail ! ( "type {} is not composite" , ecx. humanize_scalar_type( & ty) ) ,
3421+ ty => sql_bail ! (
3422+ "type {} is not composite" ,
3423+ ecx. humanize_scalar_type( & ty, false )
3424+ ) ,
34223425 } ;
34233426 let mut skip_cols: BTreeSet < ColumnName > = BTreeSet :: new ( ) ;
34243427 if let Expr :: Identifier ( ident) = sql_expr. as_ref ( ) {
@@ -3998,14 +4001,14 @@ fn plan_field_access(
39984001 ScalarType :: Record { fields, .. } => fields. iter ( ) . position ( |( name, _ty) | * name == field) ,
39994002 ty => sql_bail ! (
40004003 "column notation applied to type {}, which is not a composite type" ,
4001- ecx. humanize_scalar_type( ty)
4004+ ecx. humanize_scalar_type( ty, false )
40024005 ) ,
40034006 } ;
40044007 match i {
40054008 None => sql_bail ! (
40064009 "field {} not found in data type {}" ,
40074010 field,
4008- ecx. humanize_scalar_type( & ty)
4011+ ecx. humanize_scalar_type( & ty, false )
40094012 ) ,
40104013 Some ( i) => Ok ( expr
40114014 . call_unary ( UnaryFunc :: RecordGet ( expr_func:: RecordGet ( i) ) )
@@ -4038,11 +4041,15 @@ fn plan_subscript(
40384041 ) ,
40394042 ScalarType :: Jsonb => plan_subscript_jsonb ( ecx, expr, positions) ,
40404043 ScalarType :: List { element_type, .. } => {
4041- let elem_type_name = ecx. humanize_scalar_type ( element_type) ;
4044+ // `elem_type_name` is used only in error msgs, so we set `postgres_compat` to false.
4045+ let elem_type_name = ecx. humanize_scalar_type ( element_type, false ) ;
40424046 let n_layers = ty. unwrap_list_n_layers ( ) ;
40434047 plan_subscript_list ( ecx, expr, positions, n_layers, & elem_type_name)
40444048 }
4045- ty => sql_bail ! ( "cannot subscript type {}" , ecx. humanize_scalar_type( ty) ) ,
4049+ ty => sql_bail ! (
4050+ "cannot subscript type {}" ,
4051+ ecx. humanize_scalar_type( ty, false )
4052+ ) ,
40464053 }
40474054}
40484055
@@ -4416,7 +4423,7 @@ where
44164423 if is_unsupported_type ( & elem_type) {
44174424 bail_unsupported ! ( format!(
44184425 "cannot build array from subquery because return type {}{}" ,
4419- ecx. humanize_scalar_type( & elem_type) ,
4426+ ecx. humanize_scalar_type( & elem_type, false ) ,
44204427 vector_type_string
44214428 ) ) ;
44224429 }
@@ -4672,7 +4679,7 @@ fn plan_array(
46724679 elem_type,
46734680 ScalarType :: Char { .. } | ScalarType :: List { .. } | ScalarType :: Map { .. }
46744681 ) {
4675- bail_unsupported ! ( format!( "{}[]" , ecx. humanize_scalar_type( & elem_type) ) ) ;
4682+ bail_unsupported ! ( format!( "{}[]" , ecx. humanize_scalar_type( & elem_type, false ) ) ) ;
46764683 }
46774684
46784685 Ok ( HirScalarExpr :: CallVariadic {
@@ -4816,8 +4823,8 @@ pub fn coerce_homogeneous_exprs(
48164823 Err ( _) => sql_bail ! (
48174824 "{} could not convert type {} to {}" ,
48184825 ecx. name,
4819- ecx. humanize_scalar_type( & ecx. scalar_type( & arg) ) ,
4820- ecx. humanize_scalar_type( target) ,
4826+ ecx. humanize_scalar_type( & ecx. scalar_type( & arg) , false ) ,
4827+ ecx. humanize_scalar_type( target, false ) ,
48214828 ) ,
48224829 }
48234830 }
@@ -5334,7 +5341,7 @@ pub fn resolve_func(
53345341 let arg_types: Vec < _ > = cexprs
53355342 . into_iter ( )
53365343 . map ( |ty| match ecx. scalar_type ( & ty) {
5337- CoercibleScalarType :: Coerced ( ty) => ecx. humanize_scalar_type ( & ty) ,
5344+ CoercibleScalarType :: Coerced ( ty) => ecx. humanize_scalar_type ( & ty, false ) ,
53385345 CoercibleScalarType :: Record ( _) => "record" . to_string ( ) ,
53395346 CoercibleScalarType :: Uncoerced => "unknown" . to_string ( ) ,
53405347 } )
@@ -5713,8 +5720,8 @@ pub fn scalar_type_from_sql(
57135720 ScalarType :: String => { }
57145721 other => sql_bail ! (
57155722 "map key type must be {}, got {}" ,
5716- scx. humanize_scalar_type( & ScalarType :: String ) ,
5717- scx. humanize_scalar_type( & other)
5723+ scx. humanize_scalar_type( & ScalarType :: String , false ) ,
5724+ scx. humanize_scalar_type( & other, false )
57185725 ) ,
57195726 }
57205727 Ok ( ScalarType :: Map {
@@ -6321,8 +6328,10 @@ impl<'a> QueryContext<'a> {
63216328 }
63226329 }
63236330
6324- pub fn humanize_scalar_type ( & self , typ : & ScalarType ) -> String {
6325- self . scx . humanize_scalar_type ( typ)
6331+ /// The returned String is more detailed when the `postgres_compat` flag is not set. However,
6332+ /// the flag should be set in, e.g., the implementation of the `pg_typeof` function.
6333+ pub fn humanize_scalar_type ( & self , typ : & ScalarType , postgres_compat : bool ) -> String {
6334+ self . scx . humanize_scalar_type ( typ, postgres_compat)
63266335 }
63276336}
63286337
@@ -6397,7 +6406,9 @@ impl<'a> ExprContext<'a> {
63976406 & self . qcx . scx . param_types
63986407 }
63996408
6400- pub fn humanize_scalar_type ( & self , typ : & ScalarType ) -> String {
6401- self . qcx . scx . humanize_scalar_type ( typ)
6409+ /// The returned String is more detailed when the `postgres_compat` flag is not set. However,
6410+ /// the flag should be set in, e.g., the implementation of the `pg_typeof` function.
6411+ pub fn humanize_scalar_type ( & self , typ : & ScalarType , postgres_compat : bool ) -> String {
6412+ self . qcx . scx . humanize_scalar_type ( typ, postgres_compat)
64026413 }
64036414}
0 commit comments