@@ -1527,10 +1527,10 @@ static void
1527
1527
compatCrosstabTupleDescs (TupleDesc ret_tupdesc , TupleDesc sql_tupdesc )
1528
1528
{
1529
1529
int i ;
1530
- Form_pg_attribute ret_attr ;
1531
1530
Oid ret_atttypid ;
1532
- Form_pg_attribute sql_attr ;
1533
1531
Oid sql_atttypid ;
1532
+ int32 ret_atttypmod ;
1533
+ int32 sql_atttypmod ;
1534
1534
1535
1535
if (ret_tupdesc -> natts < 2 )
1536
1536
ereport (ERROR ,
@@ -1539,34 +1539,40 @@ compatCrosstabTupleDescs(TupleDesc ret_tupdesc, TupleDesc sql_tupdesc)
1539
1539
errdetail ("Return row must have at least two columns." )));
1540
1540
Assert (sql_tupdesc -> natts == 3 ); /* already checked by caller */
1541
1541
1542
- /* check the rowid types match */
1542
+ /* check the row_name types match */
1543
1543
ret_atttypid = TupleDescAttr (ret_tupdesc , 0 )-> atttypid ;
1544
1544
sql_atttypid = TupleDescAttr (sql_tupdesc , 0 )-> atttypid ;
1545
- if (ret_atttypid != sql_atttypid )
1545
+ ret_atttypmod = TupleDescAttr (ret_tupdesc , 0 )-> atttypmod ;
1546
+ sql_atttypmod = TupleDescAttr (sql_tupdesc , 0 )-> atttypmod ;
1547
+ if (ret_atttypid != sql_atttypid ||
1548
+ (ret_atttypmod >= 0 && ret_atttypmod != sql_atttypmod ))
1546
1549
ereport (ERROR ,
1547
1550
(errcode (ERRCODE_DATATYPE_MISMATCH ),
1548
1551
errmsg ("invalid crosstab return type" ),
1549
1552
errdetail ("Source row_name datatype %s does not match return row_name datatype %s." ,
1550
- format_type_be (sql_atttypid ),
1551
- format_type_be (ret_atttypid ))));
1553
+ format_type_with_typemod (sql_atttypid , sql_atttypmod ),
1554
+ format_type_with_typemod (ret_atttypid , ret_atttypmod ))));
1552
1555
1553
1556
/*
1554
- * - attribute [1] of the sql tuple is the category; no need to check it -
1555
- * attribute [2] of the sql tuple should match attributes [1] to [natts]
1557
+ * attribute [1] of sql tuple is the category; no need to check it
1558
+ * attribute [2] of sql tuple should match attributes [1] to [natts - 1 ]
1556
1559
* of the return tuple
1557
1560
*/
1558
- sql_attr = TupleDescAttr (sql_tupdesc , 2 );
1561
+ sql_atttypid = TupleDescAttr (sql_tupdesc , 2 )-> atttypid ;
1562
+ sql_atttypmod = TupleDescAttr (sql_tupdesc , 2 )-> atttypmod ;
1559
1563
for (i = 1 ; i < ret_tupdesc -> natts ; i ++ )
1560
1564
{
1561
- ret_attr = TupleDescAttr (ret_tupdesc , i );
1565
+ ret_atttypid = TupleDescAttr (ret_tupdesc , i )-> atttypid ;
1566
+ ret_atttypmod = TupleDescAttr (ret_tupdesc , i )-> atttypmod ;
1562
1567
1563
- if (ret_attr -> atttypid != sql_attr -> atttypid )
1568
+ if (ret_atttypid != sql_atttypid ||
1569
+ (ret_atttypmod >= 0 && ret_atttypmod != sql_atttypmod ))
1564
1570
ereport (ERROR ,
1565
1571
(errcode (ERRCODE_DATATYPE_MISMATCH ),
1566
1572
errmsg ("invalid crosstab return type" ),
1567
1573
errdetail ("Source value datatype %s does not match return value datatype %s in column %d." ,
1568
- format_type_be ( sql_attr -> atttypid ),
1569
- format_type_be ( ret_attr -> atttypid ),
1574
+ format_type_with_typemod ( sql_atttypid , sql_atttypmod ),
1575
+ format_type_with_typemod ( ret_atttypid , ret_atttypmod ),
1570
1576
i + 1 )));
1571
1577
}
1572
1578
0 commit comments