gpt4 book ai didi

sql - 在 PostgreSQL 中串联

转载 作者:行者123 更新时间:2023-11-29 11:31:36 26 4
gpt4 key购买 nike

我有一个包含宽度和高度(均为整数)的表格。我想按原样显示它。例如:宽度 = 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 COALESCE(width, '') || 'x' || COALESCE(height, '') FROM your_table;

fiddle 示例:http://sqlfiddle.com/#!15/f10eb/1/0

关于sql - 在 PostgreSQL 中串联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38495006/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com