在 PostgreSQL 中连接
Concatenate in PostgreSQL
我有一个 table 宽度和高度(均为整数)。我想按原样显示它。
例如:宽度 = 300 和高度 = 160。
面积 = 300 x 160。
我正在使用以下查询
select cast(concat(width,'x',height) as varchar(20)) from table;
或
select concat(width,'x',height) from table;
但我收到以下错误。
ERROR: function concat(character varying, "unknown", character varying) does not exist
Hint: No function matches the given name and argument types. You may need to add explicit type casts.
谁能告诉我该怎么做?
谢谢
按照||
使用https://www.postgresql.org/docs/current/static/functions-string.html
select width || 'x' || height from table;
样本fiddle:http://sqlfiddle.com/#!15/f10eb/1/0
concat()
需要字符串,而不是整数。但是你可以使用显式转换,正如错误消息所暗示的那样
select concat(width::text, 'x', height::text)
from ...
我有一个 table 宽度和高度(均为整数)。我想按原样显示它。 例如:宽度 = 300 和高度 = 160。 面积 = 300 x 160。 我正在使用以下查询
select cast(concat(width,'x',height) as varchar(20)) from table;
或
select concat(width,'x',height) from table;
但我收到以下错误。
ERROR: function concat(character varying, "unknown", character varying) does not exist
Hint: No function matches the given name and argument types. You may need to add explicit type casts.
谁能告诉我该怎么做? 谢谢
按照||
使用https://www.postgresql.org/docs/current/static/functions-string.html
select width || 'x' || height from table;
样本fiddle:http://sqlfiddle.com/#!15/f10eb/1/0
concat()
需要字符串,而不是整数。但是你可以使用显式转换,正如错误消息所暗示的那样
select concat(width::text, 'x', height::text)
from ...