mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
Add a cardinality function for arrays.
Unlike our other array functions, this considers the total number of elements across all dimensions, and returns 0 rather than NULL when the array has no elements. But it seems that both of those behaviors are almost universally disliked, so hopefully that's OK. Marko Tiikkaja, reviewed by Dean Rasheed and Pavel Stehule
This commit is contained in:
@ -1739,6 +1739,18 @@ array_length(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_INT32(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* array_cardinality:
|
||||
* returns the total number of elements in an array
|
||||
*/
|
||||
Datum
|
||||
array_cardinality(PG_FUNCTION_ARGS)
|
||||
{
|
||||
ArrayType *v = PG_GETARG_ARRAYTYPE_P(0);
|
||||
PG_RETURN_INT32(ArrayGetNItems(ARR_NDIM(v), ARR_DIMS(v)));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* array_ref :
|
||||
* This routine takes an array pointer and a subscript array and returns
|
||||
|
Reference in New Issue
Block a user