Weird behaviour

From: Vlad Arkhipov <arhipov(at)dc(dot)baikal(dot)ru>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Weird behaviour
Date: 2012-03-14 11:25:10
Message-ID: 4F608016.4020109@dc.baikal.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Could anyone please explain the behaviour of Postgres in the cases
below? It evaluates an unused expression t.x || t.y in the first case
but doesn't do it in the second one. It's also strange that the last
explain throws an error.

postgres=# select version();
version
---------------------------------------------------------------------------------------------------------------
PostgreSQL 9.1.2 on x86_64-unknown-linux-gnu, compiled by gcc (GCC)
4.1.2 20080704 (Red Hat 4.1.2-51), 64-bit
(1 row)

postgres=# create or replace function f()
postgres-# returns text as $$
postgres$# begin
postgres$# raise exception 'here';
postgres$# end;
postgres$# $$ language plpgsql immutable;

postgres=# select t.x
postgres-# from (
postgres(# select t.x, t.x || f()
postgres(# from (values(1)) as t(x)
postgres(# ) t;
ERROR: here

postgres=# select t.x
postgres-# from (
postgres(# select t.x, t.x::text || f()
postgres(# from (values(1)) as t(x)
postgres(# ) t;
x
---
1
(1 row)

postgres=# explain select t.x
postgres-# from (
postgres(# select t.x, t.x || f()
postgres(# from (values(1)) as t(x)
postgres(# ) t;
ERROR: here

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Fetter 2012-03-14 12:28:12 Re: CREATE FOREGIN TABLE LACUNA
Previous Message Andres Freund 2012-03-14 09:26:17 Re: initdb and fsync