我需要在 SQL Alchemy 中编写一个查询,以针对包含字符串数组(Postgre)的字段检查一些字符串参数
城市 州 address_line_1 邮政编码 phone_numbers
都是 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)
关于如何做的任何想法?
提前致谢!