Re: BUG #6517: Volatile function erroneously optimized, does not consider change in schema path

From: Jaime Casanova <jaime(at)2ndquadrant(dot)com>
To: rene(dot)vanpaassen(at)gmail(dot)com
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #6517: Volatile function erroneously optimized, does not consider change in schema path
Date: 2012-03-12 17:42:56
Message-ID: CAJKUy5hF0gAW=i0cR_V0swpGV9kWOeuETzkc4yhC77bO3bEjxg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Mon, Mar 5, 2012 at 6:52 AM, <rene(dot)vanpaassen(at)gmail(dot)com> wrote:
>
> set search_path to public;
>
> CREATE FUNCTION countusers()
> RETURNS INT
> AS $PROC$
> BEGIN
>    RETURN count(*) FROM users;
> END
> $PROC$ LANGUAGE 'plpgsql' VOLATILE;
>

i think you can workaround your problem using EXECUTE:

CREATE FUNCTION countusers()
RETURNS INT
AS $PROC$
DECLARE
counter INT;
BEGIN
EXECUTE 'SELECT count(*) FROM users' INTO counter;
   RETURN counter;
END
$PROC$ LANGUAGE 'plpgsql' VOLATILE;

--
Jaime Casanova         www.2ndQuadrant.com
Professional PostgreSQL: Soporte 24x7 y capacitación

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message samuel.gilbert 2012-03-12 19:34:20 BUG #6527: Error in COPY documentation syntax
Previous Message Stefano Baccianella 2012-03-12 17:38:08 Re: BUG #6512: Bug with prepared statement and timestamp + interval