0

Here is my sql statement

SELECT m.id 
FROM (SELECT id, plu FROM product) t 
   join position m ON m.plu_id LIKE '%' + @t.plu

but got such error operator does not exist: @ character varying

This answer did not help

5
  • What is this variable? Where is @t declared? What is it? What is @t.plu? Commented Oct 23, 2020 at 10:42
  • 1
    The string concatenation operator in SQL is ||. The + is to add numbers. And @ is invalid in an identifier in SQL as well. Commented Oct 23, 2020 at 10:49
  • 1
    Unrelated to your question, but: the sub-select is completely useless. You can simplify that to select .. from product t join position m ... Commented Oct 23, 2020 at 10:50
  • @underscore_d - I want to compare plu from position and plu from product Commented Oct 23, 2020 at 10:52
  • @a_horse_with_no_name - thanks, your comment helped. You can post an answer and I will accept it Commented Oct 23, 2020 at 10:55

1 Answer 1

1

The + operator in Postgres -- and in SQL in general -- is addition of numbers. That SQL Server extends this definition to include string concatenation is bespoke syntax for that database (and Sybase).

Use the correct candidate operator:

ON m.plu_id LIKE '%@' || t.plu

I assume that the @ is really a constant character that should be part of the pattern.

Sign up to request clarification or add additional context in comments.

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.