+
+CREATE OR REPLACE FUNCTION exportform(word) RETURNS text AS $$
+ SELECT concat(
+ $1.prio || CASE WHEN $1.cover THEN 'c' ELSE '' END || ':',
+ array_to_string($1.form || $1.alt, '/')
+ );
+$$ LANGUAGE SQL IMMUTABLE;
+
+CREATE OR REPLACE VIEW _cat_words AS
+ SELECT exportform(word.*) form, sub.*, word.lang, word.ref
+ FROM word RIGHT JOIN (
+ SELECT cat id, array_agg(exportform(word.*) ORDER BY grade, form) forms
+ FROM word WHERE ref IS NULL GROUP BY cat
+ ) sub USING (id);