Re: function fails where individual statements succeed - Mailing list pgsql-sql

From Tom Lane
Subject Re: function fails where individual statements succeed
Date
Msg-id 11133.1093897977@sss.pgh.pa.us
Whole thread Raw
In response to function fails where individual statements succeed  (Rosser Schwarz <rosser.schwarz@gmail.com>)
Responses Re: function fails where individual statements succeed  (Rosser Schwarz <rosser.schwarz@gmail.com>)
List pgsql-sql
Rosser Schwarz <rosser.schwarz@gmail.com> writes:
> When we group the statements together and wrap them in
> a CREATE FUNCTION, running the function fails with:

> ERROR:  index expressions and predicates may refer only to the table
> being indexed

I believe what is happening is that the entire SQL function is parsed,
analyzed, and planned before we start to execute it.  By the time
control arrives at the CREATE INDEX command, the table named
certegy.masterpcb is not the same one that that name referred to when
the function's statements were parsed.  I haven't bothered to work out
exactly how that leads to this particular error message rather than some
other failure, but I can say that this isn't gonna work out well in general.

If you want to encapsulate this set of operations in a function, I'd
suggest using plpgsql and being careful to EXECUTE each query rather
than letting plpgsql try to cache a plan for it.
        regards, tom lane


pgsql-sql by date:

Previous
From: Rosser Schwarz
Date:
Subject: Re: function fails where individual statements succeed
Next
From: Rosser Schwarz
Date:
Subject: Re: function fails where individual statements succeed