Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;

or

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? Thanks

like image 722
Bitanshu Das Avatar asked Jul 21 '16 04:07

Bitanshu Das


People also ask

What is || in PostgreSQL?

The PostgreSQL concatenate operator ( || ) is used to concatenate two or more strings and non strings.

How do I merge first name and last name in PostgreSQL?

Let's say you want to create a single Full Name column by combining two other columns, First Name and Last Name. To combine first and last names, use the CONCATENATE function or the ampersand (&) operator.

How do I concatenate a string in a Dataframe?

By use + operator simply you can concatenate two or multiple text/string columns in pandas DataFrame. Note that when you apply + operator on numeric columns it actually does addition instead of concatenation.


1 Answers

Use || as per: https://www.postgresql.org/docs/current/static/functions-string.html

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

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

like image 111
mechanical_meat Avatar answered Sep 25 '22 16:09

mechanical_meat