Closed deathemperor closed 1 month ago
current workaround: use generated column
Function:
CREATE OR REPLACE FUNCTION mp.getArrayNamesById(mp_id uuid)
RETURNS text[]
LANGUAGE sql
IMMUTABLE
AS $function$
SELECT array_agg(name) FROM (
SELECT name FROM mp.medical_provider_names WHERE medical_provider_id = mp_id AND deleted_at IS NULL
UNION ALL (SELECT name FROM mp.medical_providers WHERE medical_provider_id = mp_id)
UNION ALL (SELECT en_name as name FROM mp.medical_providers WHERE medical_provider_id = mp_id)
)
$function$;
column:
ALTER TABLE mp.medical_providers add COLUMN names text[] generated always AS (mp.getArrayNamesById(medical_provider_id)) stored;
The solution has a draw back: names will be cached (due to immutability?). Unless main record is updated, same value is returned even new record is inserted into medical_provider_names
Hi @deathemperor, return type of computed field function must be either SETOF <table>
or BASE
type (scalar type). The text[]
is not a base type. It is a container type. Please refer to docs for more details. I'm closing this issue for now.
Version Information
Server Version: v2.41.0
Environment
OSS
What is the current behaviour?
Error when creating computed field
What is the expected behaviour?
Computed field successfully created
How to reproduce the issue?
SQL function for the computed field:
Please provide any traces or logs that could help here.
Any possible solutions/workarounds you're aware of?
No
Keywords
array type _text computed field