module Clear::SQL::Query::Select
Direct including types
Defined in:
clear/sql/query/select.crInstance Method Summary
-
#clear_distinct
Remove distinct
- #clear_force_select
- #clear_select
-
#distinct(on : String? = "")
Add DISTINCT to the SELECT part of the query
- #distinct_value : String?
- #force_select(c : Column)
-
#force_select(*__args)
Act as
#select
method, but is not cleared by#clear_select
- #force_select(**__tuple)
-
#select(*__args)
Add columns in the SELECT query.
- #select(**__tuple)
-
#set_default_table_wildcard(table : String? = nil)
In some case you want you query to return
table.*
instead of*
if no select parameters has been set.
Instance Method Detail
Add DISTINCT to the SELECT part of the query
- If
on
is blank (empty string, default), will call a simpleSELECT DISTINCT ...
- If
on
is nil, will remove the distinct (see#clear_distinct
) - If
on
is a non empty string, will callSELECT DISTINCT ON (on) ...
Act as #select
method, but is not cleared by #clear_select
This is useful for enriching a query which absolutely need some key colums, for example this is used in relations caching under the hood.
query.force_select("id")
query.select("a, b").to_sql # => Output "SELECT a, b, id"
query.clear_select.to_sql # => Output "SELECT *, id"
Add columns in the SELECT query.
By default, a new SELECT query will select all using wildcard *
.
After a call to select is made, the query will select the given fields instead.
select(user_id: "uid", updated_at: "updated_at")
# => Output "SELECT user_id as uid, updated_at as updated_at"
In some case you want you query to return table.*
instead of *
if no select parameters has been set. This occurs in the case of joins
between models.