postgresql LIKE 列名上带有 %
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13274679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
LIKE with % on column names
提问by user1806801
Here is my query that results in a syntax error:
这是我的查询导致语法错误:
SELECT *
FROM account_invoice,sale_order
WHERE sale_order.name LIKE %account_invoice.origin%
The account_invoice.origin field contains the text of sale_order.name, plus other text as well, so I need to match sale_order.name string anywhere in the account_invoice.origin string.
account_invoice.origin 字段包含 sale_order.name 的文本,以及其他文本,所以我需要匹配 account_invoice.origin 字符串中的任何地方的 sale_order.name 字符串。
I'm using PostgreSQL 8.4.
我正在使用 PostgreSQL 8.4。
回答by Marc
Try this
尝试这个
SELECT *
FROM account_invoice,sale_order
WHERE sale_order.name LIKE '%' || account_invoice.origin || '%'
%
needs single quote because the pattern is a string.
%
需要单引号,因为模式是一个字符串。
||
is the operator for concatenation.
||
是连接运算符。