SP_6721
Honored Contributor II

Hi @turagittech ,

concat_ws() is generally the most practical and reliable option here. It handles mixed datatypes well and safely skips nulls. The only edge cases you'd typically run into are with complex or unsupported custom datatypes or if the separator itself is NULL.

The performance difference you noticed is likely due to caching, whichever query runs second tends to benefit from the data already being cached. to_json() is more suited for nested or complex row structures.