0

I want to execute the following update query at PostgreSQL db but it does not work and gives syntax error.

Query as follows

update wl_user set role_bitmask= role_bitmask|=1 where email='[email protected]'

Problem seems to be with |= operator, does anybody have idea how to use |= operator in PostgreSQL?

Following is the error.

[Err] ERROR:  operator does not exist: integer |= integer
LINE 1: ...pdate wl_user set role_bitmask=role_bitmask|=1 where ...
                                                             ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

1 Answer 1

3

Instead of role_bitmask= role_bitmask|=1 you must use role_bitmask=role_bitmask|1 which also makes some sense if you think what |= does and what | does.

To clarify: PostgreSQL has a lot of operators and allow you to define new operators. But in your case this does not matter for two reasons:

  • The manual for UPDATE says about the syntax (abbreviated): UPDATE ... table ... SET column = { expression | DEFAULT }. This means, that the = is mandatory and not any of the normal operators. Therefore there is no |= and no &= .
  • Among all those extensible operators there is no assignment operator. Assignment is handled in a special way for each case. Have a look at this question for some hints.

Regarding your question: An expression like role_bitmask= role_bitmask|=1 make eyebrows raise in every language :-)

Summary: You have to use the long form ... SET column = colum | bitmask.

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.