neuralib.sqlp.stat_start.select_from

neuralib.sqlp.stat_start.select_from(table: type[T], *, distinct: bool = False) SqlSelectStat[T][source]
neuralib.sqlp.stat_start.select_from(table: SqlCteExpr, *, distinct: bool = False) SqlSelectStat[tuple]
neuralib.sqlp.stat_start.select_from(*field, distinct: bool = False, from_table: str | type | SqlAlias | SqlSelectStat = None) SqlSelectStat[tuple]

SELECT: https://www.sqlite.org/lang_select.html

Select all fields from a table

>>> select_from(A).build() 
SELECT * FROM A
>>> select_from(A).fetchall() 
[A(...), A(...), ...]

Select subset of fields from A

>>> select_from(A.a, A.b).build() 
SELECT A.a, A.b FROM A
>>> select_from(A.a, A.b).fetchall() 
[('a', 1), ('b', 2), ...]

With a literal value

>>> select_from(A.a, 0).build() 
SELECT A.a, 0 FROM A
>>> select_from(A.a, 0).fetchall() 
[('a', 0), ('b', 0), ...]

With SQL functions

>>> select_from(A.a, count()).build() 
SELECT A.a, COUNT(*) FROM A

Use table alias

>>> a = alias(A, 'a') 
>>> select_from(a.a).build() 
SELECT a.a from A a

join other tables

>>> select_from(A.a, B.b).join(A.c == B.c).build() 
SELECT A.a, B.b FROM A JOIN B ON A.c = B.c

features supporting

  • SELECT DISTINCT

  • FROM

  • WHERE

  • GROUP BY

  • HAVING

  • WINDOW

  • compound-operator: UNION [ALL], INTERSECT and EXCEPT

  • ORDER BY

  • LIMIT [OFFSET]

features not supporting

  • WITH [RECURSIVE]

  • SELECT ALL

  • VALUES

Parameters:
  • args

  • distinct

  • from_table

Returns: