2011-10-28 81 views
0

我想在PostgreSQL數據庫中執行以下更新查詢,但它不起作用並給出語法錯誤。PostgreSQL如何使用按位運算符| =

查詢如下

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

問題似乎是|=運營商,沒有任何人有知道如何使用| =在PostgreSQL的操作?

以下是錯誤。

[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. 

回答

2

而不是role_bitmask= role_bitmask|=1,如果你認爲什麼|=做什麼|做你必須使用role_bitmask=role_bitmask|1這也有一定道理。

澄清:PostgreSQL有很多操作符,允許你定義新的操作符。但是,在你的情況下,這並不重要,原因有二:

  • UPDATE手冊上說有關語法(略):UPDATE ... table ... SET column = { expression | DEFAULT }。這意味着,=是強制性的,而不是的任何正常運營商。因此沒有|=,也沒有&=
  • 在所有這些可擴展運算符中,沒有賦值運算符。對於每種情況,分配都是以特殊方式處理的。看看this question的一些提示。

關於你的問題:像role_bitmask= role_bitmask|=1一種表達可使眉毛籌集:-)

摘要每一種語言:您必須使用長格式... SET column = colum | bitmask