Why is this SELECT evaluated?

Поиск
Список
Период
Сортировка
От Miles Elam
Тема Why is this SELECT evaluated?
Дата
Msg-id CAALojA-nHoxDr7B2k0e1-EtGMPsGPZiCVeS_ds0aHG0SEOrPxg@mail.gmail.com
обсуждение исходный текст
Ответы Re: Why is this SELECT evaluated?  (Christophe Pettus <xof@thebuild.com>)
Список pgsql-general
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



В списке pgsql-general по дате отправления:

Предыдущее
От: Ron
Дата:
Сообщение: Re: Indexes mysteriously change to ON ONLY
Следующее
От: Erik Wienhold
Дата:
Сообщение: Re: Why is this SELECT evaluated?