Next Prev Up Top Contents Index

select

Function
Summary

Selects data from a database given a number of specified constraints.

Package

sql

Signature

select &rest selections &key all flatp set-operation distinct from where group-by having order-by database => result-list

Arguments

selections

A set of database identifiers or strings.

all

A boolean.

flatp

A boolean.

set-operation

An SQL operation.

distinct

A boolean.

from

An SQL table.

where

An SQL condition.

group-by

An SQL condition.

having

An SQL condition.

order-by

An SQL condition.

database

A database.

Values

result-list

A list of selections.

Description

The function select selects data from database , which has a default value of *default-database* , given the constraints specified by the rest of the arguments. It returns a list of objects as specified by selections . By default, the objects will each be represented as lists of attribute values. The argument selections consists either of database-identifiers or literal strings.

The flatp argument, which has a default value of nil , specifies if full bracketed results should be returned for each matched entry. If flatp is nil , the results are returned as a list of lists. If flatp is t , the results are returned as elements of a list, only if there is only one result per row. See the examples section for an example of the use of flatp .

The arguments all , set-operation , distinct , from , where , group-by , having and order-by have the same function as the equivalent SQL expression.

The select function is common across both the functional and object-oriented SQL interfaces. If selections refers to view classes then the select operation becomes object-oriented.This means that select returns a list of view-class instances, and slot-value becomes a valid SQL operator for use within the where clause.

SQL expressions used in the select function are specified using the square bracket syntax, once this syntax has been enabled using enable-sql-reader-syntax.

Examples

The following is a potential query and result:

(select [person_id] [surname] :from [person]) => ((111 "Brown") (112 "Jones") (113 "Smith"))

In the next example, the flatp argument is set to t , and the result is a simple list of surname values:

(select [surname] :from [person] :flatp t) => ("Brown" "Jones" "Smith")
See also

print-query


LispWorks Reference Manual (Windows version) - 14 Dec 2001

Next Prev Up Top Contents Index