galiolio
galiolio

Reputation: 275

Concat two json fields in one column in POSTGRESQL 9.6

Hello here is my query :

SELECT id,objecttype,(content->>'ip' || content->>'mask') as content,  FROM public."Route"

I'd like to concat these two json fields (ip,mask) but with a space betwen them. I tried to use concat function, it works but I don't have the space between.

This is the error generate from the query above :

ERROR:  operator does not exist: text ->> unknown
LINE 1: SELECT id,objecttype,(content->>'ip' || content->>'ip') as c...

The query works well with only one field, but I need two have the concatenation between these fields with a space between them.

Thanks

Upvotes: 1

Views: 497

Answers (1)

Youcef LAIDANI
Youcef LAIDANI

Reputation: 60046

You can use cast :

SELECT id, 
       objecttype, 
       (cast(content->>'ip' as text) || ' ' || cast(content->>'mask' as text)) as content 
FROM public."Route"

Upvotes: 1

Related Questions