[英]PL/pgSQL function returns incorrect bitwise result
I have a PL/pgSQL function callbackfunc
. 我有一个PL / pgSQL函数
callbackfunc
。 If I run it with bitwise result and unpack the result in my app, I got 65/0/65/65
(which is 1090535745
). 如果我使用按位结果运行它并在我的应用程序中解压缩结果,我得到
65/0/65/65
(即1090535745
)。 If I return directly result of bitwise operation ( 1094795585
) and unpack it, I got 65/65/65/65
. 如果我直接返回按位操作的结果(
1094795585
)并将其解压缩,我得到了65/65/65/65
。 Why? 为什么?
See sample below 见下面的示例
CREATE OR REPLACE FUNCTION callbackfunc(value double precision[][][], pos integer[][], VARIADIC userargs text[])
RETURNS double precision
AS $$
DECLARE
var_result double precision;
BEGIN
var_result := (65 << 24 | 65 << 16 | 65 << 8 | 65 << 0);
--var_result := 1094795585;
RETURN var_result;
END;
$$ LANGUAGE 'plpgsql' IMMUTABLE;
It's the operator's precedence. 这是运营商的优先权。 Bitwise-Or is higher than Shift.
Bitwise-Or高于Shift。 Your expression will be calculated as
您的表达式将按计算
var_result := (((((((65 << 24) | 65) << 16) | 65) << 8) | 65) << 0);
which gives 1090535745 (= 0x41004141). 得到1090535745(= 0x41004141)。 On the opposite
相反
var_result := (65 << 24) | (65 << 16) | (65 << 8) | (65 << 0)
gives 1094795585 (= 0x41414141). 给出1094795585(= 0x41414141)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.