support_functions
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| support_functions [2012/08/25 07:54] – [tag_path(int): extract the tag name with its hierarchy] daniel | support_functions [2018/04/20 11:17] (current) – Add child_tags daniel | ||
|---|---|---|---|
| Line 27: | Line 27: | ||
| < | < | ||
| will retrieve all tags sorted and formatted as in the " | will retrieve all tags sorted and formatted as in the " | ||
| - | ====== tag_depth(int): returns | + | |
| + | |||
| + | ====== tag_depth(int) | ||
| + | **Returns | ||
| This recursive function takes the ID of a tag and returns its depth inside its hierarchy, starting by 1 for top-level tags. | This recursive function takes the ID of a tag and returns its depth inside its hierarchy, starting by 1 for top-level tags. | ||
| Line 49: | Line 52: | ||
| </ | </ | ||
| - | ====== tag_id(text): returns | + | ====== tag_id(text) |
| + | **Returns | ||
| This is the inverse function of tag_path(int). | This is the inverse function of tag_path(int). | ||
| If the name is not found, it returns null. | If the name is not found, it returns null. | ||
| Line 69: | Line 73: | ||
| </ | </ | ||
| - | ====== | + | ====== |
| + | **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 | ||
| + | </ | ||
| + | |||
| + | ====== get_header_line() ====== | ||
| + | **Extract entries from a mail header.** \\ | ||
| This function takes a mail_id and the name of a header field and returns all corresponding header entries for this message. | This function takes a mail_id and the name of a header field and returns all corresponding header entries for this message. | ||
| Line 75: | Line 100: | ||
| CREATE FUNCTION get_header_line(int, | CREATE FUNCTION get_header_line(int, | ||
| AS $$ | AS $$ | ||
| - | | + | |
| FROM header WHERE mail_id=$1; | FROM header WHERE mail_id=$1; | ||
| $$ LANGUAGE sql; | $$ LANGUAGE sql; | ||
| </ | </ | ||
support_functions.1345881271.txt.gz · Last modified: 2012/08/25 07:54 by daniel
