Bitanshu Das Bitanshu Das - 1 year ago 143
SQL Question

Concatenate in PostgreSQL

I have a table with width and height (both integers). I want to display it as are.
For eg: width = 300 and height = 160.
Area = 300 x 160.
I am using the following query

select cast(concat(width,'x',height) as varchar(20)) from table;


select concat(width,'x',height) from table;

but I am getting the following error.

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.

Can anyone tell me how to do this?

Answer Source

Use || as per:

select width || 'x' || height from table;

Sample fiddle:!15/f10eb/1/0

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download