Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

N1QL: Couchbase: How to use concat function with mixed typed

I am using couchbase and trying to concat mixed types

Example

SELECT CONCAT("abc",1, "ghi") AS concat;

RETURNS

[
  {
    "concat": null
  }
]

I am expecting

[
  {
    "concat": abc1ghi
  }
]

How do I achieve this?

like image 969
Santhosh Avatar asked Jan 22 '26 03:01

Santhosh


1 Answers

Concat() can be done on strings only, use explicit cast with type conversion functions https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/typefun.html#type-conversion-functions

For string TO_STR(), TO_STRING(), TOSTR(), TOSTRING() (synonms)

SELECT CONCAT("abc",TO_STR(1), "ghi") AS concat;

With separator and flatten the ARRAY of strings before concat

SELECT CONCAT2("-","abc",TO_STR(1), ["ghi", "xyz"] ) AS concat;
like image 75
vsr Avatar answered Jan 25 '26 20:01

vsr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!