Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
–
–
In PostgreSQL version 8.4 to String concatenation use
||
operation.
Example:
'Post' || 'greSQL'
Result is:
PostgreSQL
You could also use
WS_CONCAT
function but it is not defined in 8.4. You can declare it as the following:
CREATE OR REPLACE FUNCTION concat_ws(
separator text,
VARIADIC names_array text[]
RETURNS text
LANGUAGE plpgsql
AS $$
BEGIN
RETURN array_to_string(array_remove(names_array, NULL), ' ');
This definition works exactly as in 9.x and above: pass the separator text first and then an arbitrary amount of texts to concat. NULL
values get filtered out.
Example:
SELECT WS_CONCAT(' ', 'Ford', 'Focus', NULL /* Missing body-style */, '1.8 L')
Result: Ford Focus 1.8 L
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.