postgresql 在 postgres 中的 WHERE 子句中连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17580266/
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
Concat inside a WHERE clause in postgres
提问by user2233540
I have a question about concat function in PostgreSQL.
我有一个关于 PostgreSQL 中的 concat 函数的问题。
This sentence works well in MySQL:
这句话在 MySQL 中效果很好:
SELECT * FROM words
WHERE CONCAT (word,' ',gender,' ',semantic) LIKE '%"+value+"%'.
Value is a variable that is changed inside my Java program.
值是在我的 Java 程序中更改的变量。
But I need the same working in postgresql. How kann I concatenate inside the WHERE clause, using postgres, considering the variable "value" that will have its value changed ?
但我需要在 postgresql 中进行同样的工作。考虑到将更改其值的变量“值”,我如何使用 postgres 在 WHERE 子句中连接?
回答by
In Postgresql you concatenate using the following syntax:
在 Postgresql 中,您使用以下语法进行连接:
(users.first_name || ' ' || users.last_name)
Reference: http://www.postgresql.org/docs/9.1/static/functions-string.html
参考:http: //www.postgresql.org/docs/9.1/static/functions-string.html
回答by J. Sanchez
You can also use this for postgresql:
您也可以将其用于 postgresql:
concat_ws(' ', campo1, campo2) like '%value%'
Note that there is a space between single quotes
注意单引号之间有一个空格