Python 从sqlalchemy core中的函数调用中选择列

Python 从sqlalchemy core中的函数调用中选择列,python,sql,postgresql,stored-procedures,sqlalchemy,Python,Sql,Postgresql,Stored Procedures,Sqlalchemy,在postgresql中,我有从我的函数()中选择col1、col2。在sqlalchemy core中如何实现这一点 select(func.my_function())以字符串形式给出结果,但我需要一个元组。您需要使用和轻量级: 文档中特别提到Postgresql作为此构造的用例。上述结果产生: SELECT col1, col2 FROM my_function() AS anon_1 使用column()的参数_selective,您还可以: In [4]: fn = func.my

在postgresql中,我有
从我的函数()中选择col1、col2
。在sqlalchemy core中如何实现这一点

select(func.my_function())
以字符串形式给出结果,但我需要一个元组。

您需要使用和轻量级:

文档中特别提到Postgresql作为此构造的用例。上述结果产生:

SELECT col1, col2 
FROM my_function() AS anon_1
使用
column()
的参数_selective,您还可以:

In [4]: fn = func.my_function().alias()

In [5]: stmt = select([column('col1', _selectable=fn),
   ...:                column('col2', _selectable=fn)])

In [6]: print(stmt)
SELECT anon_1.col1, anon_1.col2 
FROM my_function() AS anon_1

但由于_selective没有文档记录,这可能不是一个好主意。

它往往不能很好地与SPs配合使用,我记得我放弃了这一点,并运行了原始命令。
In [4]: fn = func.my_function().alias()

In [5]: stmt = select([column('col1', _selectable=fn),
   ...:                column('col2', _selectable=fn)])

In [6]: print(stmt)
SELECT anon_1.col1, anon_1.col2 
FROM my_function() AS anon_1