select &rest selections &key all flatp set-operation distinct from where group-by having order-by database => result-list
A set of database identifiers or strings.
A boolean.
A boolean.
An SQL operation.
A boolean.
An SQL table.
An SQL condition.
An SQL condition.
An SQL condition.
An SQL condition.
A database.
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.
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")