我正在尝试从子查询中选择一列(下面的代码)。
import sqlalchemy as sa
table1 = sa.schema.Table('t1',
db,
autoload=True,
autoload_with=db.engine)
si = Query().cte()
pids = sa.select([t1.c.pid], distinct=True).where(t1.c.date > date)
jt = pids.join(
si,
(si.c.pid == t1.c.pid) &
(si.c.startdate <= date) &
(si.c.enddate > date))
return sa.select([si.c.id]).select_from(jt)
但是,我总是收到如下错误:
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) subquery in FROM must have an alias
LINE 6: FROM (SELECT DISTINCT t1.pid AS pid
^
HINT: For example, FROM (SELECT ...) [AS] foo.
我应该如何为子查询添加别名?