Alex.U
Alex.U

Reputation: 1701

Concatenating to a positional parameter in Postgres

Is there a simpler way in Postgres to concatenate to a positional parameter?

I came up with this solution:

to_tsquery('english', concat($1::text, ':*'))

And was wondering if there is a more idiomatic way to achieving the same end.

Upvotes: 1

Views: 61

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 247515

That seems ok, as long as you handle any error messages coming from syntactically incorrect queries.

One problem is that concat is not STRICT, so you will get :* for NULL values. It might be better to use

to_tsquery('english', $1 || ':*'))

Upvotes: 2

Related Questions