Re: table name as function argument?

From: John DeSoi <desoi(at)pgedit(dot)com>
To: "Les Carter" <les(dot)carter(at)help-me(dot)to>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: table name as function argument?
Date: 2005-02-09 06:55:51
Message-ID: A2D47BDE-7A67-11D9-9303-000A95B03262@pgedit.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Les,

On Feb 5, 2005, at 9:21 PM, Les Carter wrote:

> Hi, I'm fairly new to postgres and was wondering how would I go about
> using an argument passed into a user function to refer to a table.
>
> As an example, consider the code below where I want to see if a table
> has any rows in it (this isn't what I'm trying to achieve but just the
> easiest thing I could think of to demonstrate what my problem is).

You need to use EXECUTE for cases where the table references cannot be
resolved when the function is created. See:

http://www.postgresql.org/docs/8.0/interactive/plpgsql-
statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN

Note that EXECUTE can't return results, but this section points you to
the relevant solutions.

John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Michael Fuhr 2005-02-09 07:40:17 Re: Text type versus Varchar(n)
Previous Message Kevin Crenshaw 2005-02-09 04:09:09 Text type versus Varchar(n)