support_functions
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| support_functions [2017/05/26 11:46] – [get_header_line()] daniel | support_functions [2018/04/20 11:17] (current) – Add child_tags daniel | ||
|---|---|---|---|
| Line 71: | Line 71: | ||
| END; | END; | ||
| $$ LANGUAGE plpgsql STABLE STRICT; | $$ LANGUAGE plpgsql STABLE STRICT; | ||
| + | </ | ||
| + | |||
| + | ====== child_tags(int) ====== | ||
| + | **Return all childs of a tag.** \\ | ||
| + | Takes the ID of a tag or null to designate the root of all tags. Returns | ||
| + | the set of child tags. | ||
| + | |||
| + | <file sql child_tags.sql> | ||
| + | create function child_tags(top_id integer) returns setof integer | ||
| + | as $$ | ||
| + | WITH RECURSIVE tagr(_tag_id) as ( | ||
| + | | ||
| + | from tags where parent_id is not distinct from top_id | ||
| + | UNION ALL | ||
| + | | ||
| + | | ||
| + | FROM tags JOIN tagr ON tagr._tag_id=tags.parent_id | ||
| + | ) | ||
| + | select _tag_id FROM tagr; | ||
| + | $$ language sql stable | ||
| </ | </ | ||
support_functions.1495799211.txt.gz · Last modified: 2017/05/26 11:46 by daniel
