i have e.g. a table "Employee" with
last_name :: character varying
handed_texts :: text[]
Where text is an own data-type with "("Date", title/not_exist)".
There could be x entries while x := ({}, 1,2,...)
Example:
jones , {"(2017-01-01, stars_in_univ)", "(2017-01-01, not_exist)", "(2017-01-02, unemployed ants)"}
tomes , {"(2017-01-01, not_exist)", "(2017-01-08, shared_minds)"}
My Problem now: i want to count the existing texts for each name. I tried e.g. something like that:
SELECT last_name, handed_texts,
CASE
WHEN handed_texts IS NULL THEN 0
ELSE
FOREACH i IN ARRAY handed_texts
DECLARE c integer;
SET c = 0;
LOOP
IF i NOT LIKE '%not_exist%' THEN c+1 ELSE c END IF
return c
END LOOP
END AS counted_texts
FROM employee
I know the declaration is totally wrong, but i couldn't find any way to declare a variable in a way that my system accepts so i just wrote it at the place i think it should be declared. The other way i tried to count was to make a new array where i just put the correct/wanted record in and use array_length, but that seems to be even more catastrophal than the e.g above.