Re: Problem calling stored procedure - Mailing list pgsql-sql

From Tom Lane
Subject Re: Problem calling stored procedure
Date
Msg-id 2023.1124806015@sss.pgh.pa.us
Whole thread Raw
In response to Re: Problem calling stored procedure  (<neil.saunders@accenture.com>)
List pgsql-sql
<neil.saunders@accenture.com> writes:
> OPEN cur_overlap FOR SELECT *, pg_class.RELNAME AS table FROM calendar_entries WHERE (start_date, end_date) OVERLAP
(new_start_date,new_end_date) AND property_id = X AND pg_class.oid = tableoid;
 

> The only thing I can think of is that when the query runs in the psql I get:
> NOTICE: added missing FROM-clause entry for table "pg_class"

> I understand why this is happening, but don't know how I would go
> about re-writing the query to explicitly reference pg_class - I can't
> write calendar_entries.table_oid, because that changes the meaning of
> the query.

How so?  It'd be the same as far as I can see.

However, you could avoid any explicit use of pg_class by using the
regclass type instead:

OPEN cur_overlap FOR SELECT *, tableoid::regclass AS table FROM calendar_entries WHERE (start_date, end_date) OVERLAP
(new_start_date,new_end_date) AND property_id = X;
 

As far as the reason for the difference between function execution and
manual execution: check for unintended variable substitutions.  Which
words in the query match variable names in the plpgsql function?  Are
those only the ones you intended?
        regards, tom lane


pgsql-sql by date:

Previous
From:
Date:
Subject: Re: Problem calling stored procedure
Next
From: Szűcs Gábor
Date:
Subject: Tuple insert missing query in ongoing transaction