I tried to create an immutable CONCAT(). For this, I tried to use the following SQL queries.
Option 1
CREATE FUNCTION immutable_concat(VARIADIC text[])
RETURNS text
LANGUAGE internal IMMUTABLE PARALLEL SAFE AS 'text_concat';
Option 2
CREATE FUNCTION immutable_concat(VARIADIC text[])
RETURNS text
LANGUAGE sql IMMUTABLE PARALLEL SAFE
RETURN array_to_string($1, '');
As a result, I get a function that works well with text. But how can I create a similar function that will take an array containing not only text elements?
CONCAT() allows us to execute the following SQL query:
SELECT concat(CURRENT_DATE, true, false, 1, 'text');
As a result, we will get the following string:
2025-03-07tf1text
Ideally, I would like to create a function that can take different elements. I mean the following:
SELECT immutable_concat(CURRENT_DATE, true, false, 1, 'text');
anyarray.