Copyright | (c) Eitan Chatav 2019 |
---|---|
Maintainer | eitan@morphism.tech |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
select statements
Synopsis
- select :: (SListI row, row ~ (x ': xs)) => Selection grp lat with db params from row -> TableExpression grp lat with db params from -> Query lat with db params row
- select_ :: (SListI row, row ~ (x ': xs)) => NP (Aliased (Expression grp lat with db params from)) row -> TableExpression grp lat with db params from -> Query lat with db params row
- selectDistinct :: (SListI columns, columns ~ (col ': cols)) => Selection grp lat with db params from columns -> TableExpression grp lat with db params from -> Query lat with db params columns
- selectDistinct_ :: (SListI columns, columns ~ (col ': cols)) => NP (Aliased (Expression grp lat with db params from)) columns -> TableExpression grp lat with db params from -> Query lat with db params columns
- selectDistinctOn :: (SListI columns, columns ~ (col ': cols)) => [SortExpression grp lat with db params from] -> Selection grp lat with db params from columns -> TableExpression grp lat with db params from -> Query lat with db params columns
- selectDistinctOn_ :: (SListI columns, columns ~ (col ': cols)) => [SortExpression grp lat with db params from] -> NP (Aliased (Expression grp lat with db params from)) columns -> TableExpression grp lat with db params from -> Query lat with db params columns
- data Selection grp lat with db params from row where
- Star :: HasUnique tab from row => Selection 'Ungrouped lat with db params from row
- DotStar :: Has tab from row => Alias tab -> Selection 'Ungrouped lat with db params from row
- List :: SListI row => NP (Aliased (Expression grp lat with db params from)) row -> Selection grp lat with db params from row
- Over :: SListI row => NP (Aliased (WindowFunction grp lat with db params from)) row -> WindowDefinition grp lat with db params from -> Selection grp lat with db params from row
- Also :: Selection grp lat with db params from right -> Selection grp lat with db params from left -> Selection grp lat with db params from (Join left right)
Select
:: (SListI row, row ~ (x ': xs)) | |
=> Selection grp lat with db params from row | selection |
-> TableExpression grp lat with db params from | intermediate virtual table |
-> Query lat with db params row |
the TableExpression
in the select
command constructs an intermediate
virtual table by possibly combining tables, views, eliminating rows,
grouping, etc. This table is finally passed on to processing by
the select list. The Selection
determines which columns of
the intermediate table are actually output.
:: (SListI row, row ~ (x ': xs)) | |
=> NP (Aliased (Expression grp lat with db params from)) row | select list |
-> TableExpression grp lat with db params from | intermediate virtual table |
-> Query lat with db params row |
Like select
but takes an NP
list of Expression
s instead
of a general Selection
.
:: (SListI columns, columns ~ (col ': cols)) | |
=> Selection grp lat with db params from columns | selection |
-> TableExpression grp lat with db params from | intermediate virtual table |
-> Query lat with db params columns |
After the select list has been processed, the result table can
be subject to the elimination of duplicate rows using selectDistinct
.
:: (SListI columns, columns ~ (col ': cols)) | |
=> NP (Aliased (Expression grp lat with db params from)) columns | select list |
-> TableExpression grp lat with db params from | intermediate virtual table |
-> Query lat with db params columns |
Like selectDistinct
but takes an NP
list of Expression
s instead
of a general Selection
.
:: (SListI columns, columns ~ (col ': cols)) | |
=> [SortExpression grp lat with db params from] | DISTINCT ON expression(s) and prepended to ORDER BY clause |
-> Selection grp lat with db params from columns | selection |
-> TableExpression grp lat with db params from | intermediate virtual table |
-> Query lat with db params columns |
selectDistinctOn
keeps only the first row of each set of rows where
the given expressions evaluate to equal. The DISTINCT ON expressions are
interpreted using the same rules as for ORDER BY. ORDER BY is used to
ensure that the desired row appears first.
The DISTINCT ON expression(s) must match the leftmost ORDER BY expression(s). The ORDER BY clause will normally contain additional expression(s) that determine the desired precedence of rows within each DISTINCT ON group.
In order to guarantee they match and reduce redundancy, this function will prepend the The DISTINCT ON expressions to the ORDER BY clause.
:: (SListI columns, columns ~ (col ': cols)) | |
=> [SortExpression grp lat with db params from] | distinct on and return the first row in ordering |
-> NP (Aliased (Expression grp lat with db params from)) columns | selection |
-> TableExpression grp lat with db params from | intermediate virtual table |
-> Query lat with db params columns |
Like selectDistinctOn
but takes an NP
list of Expression
s instead
of a general Selection
.
data Selection grp lat with db params from row where Source #
The simplest kinds of Selection
are Star
and DotStar
which
emits all columns that a TableExpression
produces. A select List
is a list of Expression
s. A Selection
could be a list of
WindowFunction
s Over
WindowDefinition
. Additional
Selection
s can
be selected with Also
.
Star | |
| |
DotStar | |
List | |
| |
Over | |
| |
Also | |
Instances
(Has tab (Join from lat) row0, Has col row0 ty, row1 ~ '[col ::: ty], GroupedBy tab col bys) => IsQualified tab col (Selection ('Grouped bys) lat with db params from row1) Source # | |
(Has tab (Join from lat) row0, Has col row0 ty, row1 ~ '[col ::: ty]) => IsQualified tab col (Selection 'Ungrouped lat with db params from row1) Source # | |
(HasUnique tab (Join from lat) row0, Has col row0 ty, row1 ~ '[col ::: ty], GroupedBy tab col bys) => IsLabel col (Selection ('Grouped bys) lat with db params from row1) Source # | |
Defined in Squeal.PostgreSQL.Query.Select | |
(HasUnique tab (Join from lat) row0, Has col row0 ty, row1 ~ '[col ::: ty]) => IsLabel col (Selection 'Ungrouped lat with db params from row1) Source # | |
Defined in Squeal.PostgreSQL.Query.Select | |
(KnownSymbol col, row ~ '[col ::: ty]) => Aliasable col (Expression grp lat with db params from ty) (Selection grp lat with db params from row) Source # | |
Defined in Squeal.PostgreSQL.Query.Select | |
Additional (Selection grp lat with db params from :: RowType -> Type) Source # | |
IsString (Selection grp lat with db params from '["fromOnly" ::: 'NotNull 'PGtext]) Source # | |
Defined in Squeal.PostgreSQL.Query.Select | |
RenderSQL (Selection grp lat with db params from row) Source # | |
Defined in Squeal.PostgreSQL.Query.Select renderSQL :: Selection grp lat with db params from row -> ByteString Source # |