sql - SQLAlchemy 加入函数 - 如何引用返回的列?
问题描述
我有一个要使用 sqlalchemy 重新创建的查询
SELECT * FROM some_table AS st
INNER JOIN MY_FUNCTION(123, 456) mf ON st.id = mf.id
INNER JOIN other_table AS ot ON st.other_id = ot.other_id
whereMY_FUNCTION
是一个返回临时表的函数。可能是由于不知道所有术语,我很难制定出 sqlalchemy 语法来重新创建这个 sql - 我知道我可以select_from()
为连接做一个,但我不确定如何使用该函数重新创建连接。
这是在 postgresql 中,但理想情况下也适用于 sqlserver。在我的脑海中,我想象它是这样的:
some_table = Table("some_table", ...)
my_function = func.my_function(123, 456)
other_table = Table("other_table", ...)
some_table.select_from(
some_table.join(
my_function,
some_table.c.id == my_function.c.id # myfunction.c.id attribute error
).join(
other_table,
some_table.c.other_id == other_table.c.other_id
)
)
编辑:我已经取得了进展,我相信 sqlalchemyfunc
将返回函数对象,但我不确定如何引用将在join()
解决方案
推荐阅读
- linux - 挂载选项条带未在 fstab 中定义
- c# - 如何在列表列表中获取最小的日期时间/值 - 使用 LINQ
- excel - Excel宏在4个月后清除单元格并且当另一个单元格被填充时
- python - 如果最后 N 个元素为 0 且为常量,则删除它们
- sql - 使用“/”字符提取数据:针对 Excel 的 SQL
- alloy - Alloy 5.0(包括 macOS High Sierra 版本)
- r - 没有找到 ksvm 的预测功能?
- python - Python根据条件合并两个Numpy数组
- python - pyspark-2.3 sparkml LogisticRegression 模型加载问题
- ios - Interface Builder 最新 Xcode 不指向最新版本