Search Postgresql Archives

Why is this SELECT evaluated?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Postgres v15

Given this example of a conversion from a byte array to an int8
masquerading as an "unsigned" int4

      SELECT (get_byte(bytes, byte_offset)::int8 << 24)
             | (get_byte(bytes, byte_offset + 1) << 16)
             | (get_byte(bytes, byte_offset + 2) << 8)
             | (get_byte(bytes, byte_offset + 3))
        FROM ( VALUES ('\x010000'::bytea, 0) ) b(bytes, byte_offset)
       WHERE length(bytes) >= (4 + byte_offset)
      ;

Why does this error result?

    ERROR: index 3 out of valid range, 0..2
    SQL state: 2202E

I was under the impression that if the WHERE clause evaluated to
false, the SELECT clause would not be evaluated. Why is get_byte(...)
ever run in the first place even though length(bytes) is 3?

- Miles Elam





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux