Next: , Previous: , Up: Query Construction   [Contents][Index]


9.6 Tree Construction

This section describes the tree construction procedures, most of which are still (at this time, 2005-02-24) considered experimental. You should take this as an invitation to experiment and share your observations w/ the Guile-PG maintainer so that we can refine them nicely for the 1.0 release.

Procedure: make-comma-separated-tree proc ls [parens? [more-ls…]]

Return a tree made by mapping proc over list ls, with elements separated by commas. Optional third arg parens? non-#f includes surrounding parentheses. The rest of the args are more lists, whose CARs are passed as additional args to proc.

Procedure: make-WHERE-tree condition

Return a where clause tree for condition.

Procedure: make-GROUP-BY-tree expressions

Return a group-by clause tree for expressions (a list).

Procedure: make-HAVING-tree conditions

Return a having clause tree for conditions (a list).

Procedure: make-ORDER-BY-tree orderings

Return a order-by clause tree for orderings (a list). Each element of orderings has the form: (ORDFUNC EXPR). If ordfunc is the symbol < or the keyword #:ASC, it is taken as ASC. Likewise, > or #:DESC is taken as DESC.

Procedure: make-SELECT/COLS-tree cols

Return a select-cols clause tree for cols (a list). Each element of cols can take one of several forms:

title

A symbol, a column name possibly qualified with the table name. For example, foo.bar means table foo, column bar.

(title . expr)

title is a string to be used to name the output for the column described by prefix-style expression expr.

expr

A prefix-style expression. The name of the output column described by expr is usually expr’s outermost function or operator.

Procedure: make-FROM-tree items

Return a from clause tree for items (a list). Each element of items, a from-item, can take one of several forms:

table-name

A symbol.

(alias . table-name)

A pair of symbols.

(jtype [jcondition] left-from right-from)

This is a join clause, where jtype is a keyword, one of #:join, #:left-join, #:right-join, #:full-join; and left-from and right-from are each a single from-item to be handled recursively. If jtype is #:join, jcondition must be omitted. Otherwise, it is one of:

#:natural
(#:using col1 col2...)
(#:on pexp)
Procedure: make-SELECT/FROM/COLS-tree froms cols

Return a select/from/col combination clause tree for froms and cols (both lists). In addition to the constituent processing done by make-SELECT/COLS-tree and make-FROM-tree on cols and froms, respectively, prefix a SELECT token. If froms is #f, it is omitted.

Procedure: parse+make-SELECT/tail-tree plist

Return a select tail tree for plist, a list of alternating keywords and related expressions. These subsequences are recognized:

#:from x

Pass x to make-FROM-tree.

#:where x

Pass x to make-WHERE-tree.

#:group-by x

Pass x to make-GROUP-BY-tree.

#:having x

Pass x to make-HAVING-tree.

#:order-by x

Pass x to make-ORDER-BY-tree.

#:limit n
#:offset n

Arrange for the tree to include LIMIT n and/or OFFSET n. n is an integer.

If an expression (x or n) is #f, omit the associated clause completely from the returned tree.

Procedure: parse+make-SELECT-tree composition cols/subs [tail…]

Return a select tree of composition for cols/subs and tail.

If composition is #t, cols/subs is passed directly to make-SELECT/COLS-tree. Otherwise, it should be one of:

#:union       #:intersect       #:except
#:union-all   #:intersect-all   #:except-all

cols/subs is a list of sublists taken as arguments to parse+make-SELECT-tree (applied recursively to each sublist), and finally combined by composition.

tail is passed directly to parse+make-SELECT/tail-tree.


Next: Output, Previous: Strings, Up: Query Construction   [Contents][Index]