1

Hello i am writting a pgsql function and inside this function , i have one request with array_to_string method.

    AND id NOT IN (array_to_string(excludeArcs,','))

ID is an integer but array_to_string return string so : Error result : operator does not exist integer <> text

Someone can help me ?

2 Answers 2

1

Your query is equivalent to id NOT IN( '1,2,3' ). You can not compare ID with string.

It is necessary to expand the array to the table:

AND id NOT IN(select * from unnest(excludeArcs))
Sign up to request clarification or add additional context in comments.

Comments

0

The transformation to string is wrong - string operation are more expensive

postgres=# select 10 = ANY(ARRAY[10,20,30]);
┌──────────┐
│ ?column? │
╞══════════╡
│ t        │
└──────────┘
(1 row)

postgres=# select 10 <> ALL(ARRAY[10,20,30]);
┌──────────┐
│ ?column? │
╞══════════╡
│ f        │
└──────────┘
(1 row)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.