postgresql Postgres 连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11715190/
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
Postgres Concatenation
提问by Phani
I'm trying to a simple concatenation in PostgreSQL and it keeps up throwing up an error message. I don't understand what I am doing wrong here.
我正在尝试在 PostgreSQL 中进行简单的连接,但它一直在抛出错误消息。我不明白我在这里做错了什么。
select concat('abcde', 'fgh');
No function matches the given name and argument types. You might need to add explicit type casts.
select concat(cast('abcde' as text), cast('fgh' as text));
No function matches the given name and argument types. You might need to add explicit type casts.
I am using Postgres version 8.4.11. Please let me know what is going on.
我使用的是 Postgres 8.4.11 版。请让我知道发生了什么。
回答by Sorrow
The concat operator is ||
, so select 'abcde' || 'fgh'
should work. Also, as @jonathan.cone suggested, check out the docs.
concat 运算符是||
,所以select 'abcde' || 'fgh'
应该可以工作。另外,正如@jonathan.cone 所建议的,请查看文档。
回答by Craig Ringer
concat
was added in 9.1, it doesn't exist in 8.4. As others have noted, use the ||
operator.
concat
在 9.1 中添加,在 8.4 中不存在。正如其他人所指出的,请使用||
运算符。
Compare the 8.4 docsto the 9.1 docsand you'll notice that the concat
function isn't present in the 8.4 docs.
将8.4 文档与9.1 文档进行比较,您会注意到该concat
函数不存在于 8.4 文档中。
See that bar at the top of the docs that says "This page in other versions" ? It's really handy when you're working with an old version, or if you find a link to an old version of a page via Google and you're on a newer version. Always make sure you're looking at the docs for the right version.
看到文档顶部的那个栏,上面写着“其他版本的这个页面”?当您使用旧版本时,或者如果您通过 Google 找到指向旧版本页面的链接并且您使用的是较新版本时,这真的很方便。始终确保您正在查看正确版本的文档。
It'd be nice if the tables for functions etc included a "First appeared in version " - but unfortunately they don't.
如果函数表等包含“首次出现在版本中”,那就太好了——但不幸的是,它们没有。
If you're ever confused about the availablilty of a function, you can use \df
in psql to list and search functions.
如果您对函数的可用性感到困惑,您可以\df
在 psql 中使用来列出和搜索函数。
For example, to list all functions named concat
use \df concat
例如,要列出所有名为concat
use 的函数\df concat
For all functions in the pg_catalog
schema (built-in functions) use \df pg_catalog.
- note the trailing period, telling psql you mean "any function within the schema pg_catalog" not "the function named pg_catalog".
对于pg_catalog
模式中的所有函数(内置函数)使用\df pg_catalog.
- 注意尾随句点,告诉 psql 你的意思是“模式 pg_catalog 中的任何函数”而不是“名为 pg_catalog 的函数”。
For all functions with names starting with concat
use \df concat*
对于名称以concat
use开头的所有函数\df concat*
It's a very powerful tool. The same language works when searching for schema (\dn
), tables (\dt
), etc.
这是一个非常强大的工具。在搜索模式 ( \dn
)、表 ( \dt
) 等时,使用相同的语言。
回答by ART GALLERY
select 'abcde' || 'fgh';
select cast('abcde' as text) || cast('fgh' as text);