Table name as parameter

From: Sairam Krishnamurthy <kmsram420(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Table name as parameter
Date: 2011-05-09 19:33:35
Message-ID: BANLkTimPP7uu4CbC651Oq90rHOuuz4YJbQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

All,

I have a function that takes the table name the parameter. After some
digging I found that this can be made possible by have the query as a string
and EXECUTE it.

EXECUTE 'SELECT * FROM "' || table || '" WHERE <condition>';

The above works.

But I want the result in a record variable for further processing. So my
query actually is

EXECUTE 'SELECT * FROM "' || table || '" INTO "record_data" WHERE
<condition>';

This one will not work with the following error message:

ERROR: syntax error at or near "INTO"

Can some one help me ?

Thanks,
Sairam Krishnamurthy
+1 612 859 8161

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2011-05-09 20:15:33 Re: simple update query too long
Previous Message Tom Lane 2011-05-09 18:12:48 Re: ALTER TABLE ... DISABLE TRIGGERS Isolation leve