neuralib.sqlp.stat.SqlSelectStat
- class neuralib.sqlp.stat.SqlSelectStat[source]
Bases:
SqlStat[T],SqlWhereStat,SqlLimitStat,Generic[T]SELECT statement.
- windows(*windows, **window_ks)[source]
define windows.
- Parameters:
windows (SqlWindowDef | SqlAlias[SqlWindowDef])
window_ks (SqlWindowDef)
- Return type:
Self
- BY
alias of
Literal[‘left’, ‘right’, ‘inner’, ‘full outer’, ‘cross’]
- join(constraint: Callable | ForeignConstraint, *, by: BY = None) SqlSelectStat[tuple][source]
- join(table: type[S] | SqlAlias[S], constraint: Callable | ForeignConstraint, *, by: BY = None) SqlSelectStat[tuple]
- join(table: type[S] | SqlSelectStat[S] | SqlAlias[S] | SqlCteExpr, *field: bool | Any, by: BY = None) SqlSelectStat[tuple]
- join(*field: bool | Any, by: BY = None) SqlSelectStat[tuple]
JOINhttps://www.sqlite.org/lang_select.html#strange_join_names>>> select_from(A.a, B.b).join(A.a == B.a) SELECT A.a, B.b FROM A JOIN B ON A.a = B.a
- group_by(*by)[source]
GROUP BYhttps://www.sqlite.org/lang_select.html#resultset- Return type:
Self
- having(*exprs)[source]
HAVINGhttps://www.sqlite.org/lang_select.html#resultset- Parameters:
exprs (bool | SqlExpr)
- Return type:
Self
- intersect(stat)[source]
INTERSECThttps://www.sqlite.org/lang_select.html#compound_select_statements- Parameters:
stat (SqlStat)
- Return type:
Self
- union(stat, all=False)[source]
UNIONhttps://www.sqlite.org/lang_select.html#compound_select_statements- Parameters:
stat (SqlStat)
- Return type:
Self
- except_(stat)[source]
EXCEPThttps://www.sqlite.org/lang_select.html#compound_select_statements- Parameters:
stat (SqlStat)
- Return type:
Self
- add(stat)
Add SQL token.
- Return type:
Self
- build()
build a SQL statement.
- Return type:
tuple[str, list]
- drop()
- limit(*args)
LIMIT: https://www.sqlite.org/lang_select.html#limitoffset>>> select_from(A).limit(10).build() SELECT * FROM A LIMIT 10 >>> select_from(A).limit(10, 10).build() SELECT * FROM A LIMIT 10 OFFSET 10
NOTE
LIMIT on UPDATE/DELETE need compile flag
SQLITE_ENABLE_UPDATE_DELETE_LIMIT.>>> assert Connection().sqlite_compileoption_used('SQLITE_ENABLE_UPDATE_DELETE_LIMIT')
- Parameters:
args (int)
- Return type:
Self
- order_by(*by)
ORDER BY: https://www.sqlite.org/lang_select.html#orderby>>> select_from(A).order_by(A.a).build() SELECT * FROM A ORDER BY A.
possible ordering
>>> select_from(A).order_by( ... asc(A.a), desc(A.b), nulls_first(A.c), asc(A.d).nulls_last(), ... ) SELECT * FROM A ORDER BY A.a ASC, A.b DESC, A.c NULLS FIRST, A.d ASC NULLS LAST
NOTE
ORDER BY on UPDATE/DELETE need compile flag
SQLITE_ENABLE_UPDATE_DELETE_LIMIT.>>> assert Connection().sqlite_compileoption_used('SQLITE_ENABLE_UPDATE_DELETE_LIMIT')
- Parameters:
by (int | str | SqlExpr | Any)
- Return type:
Self
- submit()
build the SQL statement and execute.
- Returns:
a cursor
- Raises:
RuntimeError – current statement does not bind with a connection.
- Return type:
Cursor[T]
- where(*expr)
WHEREclause: https://www.sqlite.org/lang_select.html#whereclause>>> select_from(A).where( ... A.a == 1, A.b == 2 ... ).build() SELECT * FROM A WHERE (A.a = 1) AND (A.b = 2)
- Parameters:
expr (bool | SqlCompareOper | SqlExpr | None)
- Returns:
- Return type:
Self