Postgresql 8.4 Like Concat

my query in postgresql 9.3 is:

SELECT *
    FROM route
    WHERE 'my/uri/address' LIKE CONCAT(c_uri, '%')

But in postgresql 8.4 this code not working.

How can i resolve, please?

Thanks in advance!

Upvotes: 1

Views: 1538

Answers (2)

Adam Horvath
Adam Horvath

Reputation: 1286

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), ' ');
END;
$$;

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

Upvotes: 0

BSeitkazin
BSeitkazin

Reputation: 3059

In PostgreSQL version 8.4 to String concatenation use || operation.

Example:'Post' || 'greSQL'

Result is: PostgreSQL

Upvotes: 3

Related Questions