【发布时间】:2014-02-28 05:41:31
【问题描述】:
我需要在 SQL Alchemy 中编写一个查询来针对包含字符串数组 (Postgre) 的字段检查一些字符串参数
城市 状态 地址第一行 邮政编码 电话号码
都是 text[] 类型
select_statement = bdb.get_select_statement(business_schema)\
.where(((text('array[:acity] <@ city')
and text('array[:astate] <@ state')
and text('array[:aaddress] <@ address_line_1'))
or
(text('array[:aaddress] <@ address_line_1') and text('array[:azip_code] <@ zip_code')))
and (text('array[:aphone] <@ phone_numbers')))\
.params(aaddress = address_line_1, acity = city, astate = state, azip_code = zip_code, aphone = phone_number)
问题是我在执行此操作时收到异常,“未定义此子句的布尔值”。
要写的纯SQL是:
select * from business where ('address_line1' = ANY (address_line_1)
and 'acity' = ANY (city)
and 'state' = ANY (state)
or
('adress_line1' = ANY (address_line_1) and 'zip' = ANY (zip_code))
and
'phone' = ANY (phone_numbers)
关于如何做的任何想法?,
提前致谢!
【问题讨论】:
标签: sqlalchemy