Re: function with tablename parameter

From: Adam Witney <awitney(at)sghms(dot)ac(dot)uk>
To: "hlavki(at)medium13" <hlavki(at)medium13(dot)sk>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: function with tablename parameter
Date: 2003-10-27 16:12:52
Message-ID: BBC2F484.27139%awitney@sghms.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


To use dynamic queries you will probably have to use EXECUTE, take a look
here

http://www.postgresql.org/docs/7.3/interactive/plpgsql-statements.html#PLPGS
QL-STATEMENTS-EXECUTING-DYN-QUERIES

Although that page says that EXECUTE does not support SELECT INTO queries,
but you may be able to build something using FOR-IN-EXECUTE as described in
this section:

http://www.postgresql.org/docs/7.3/interactive/plpgsql-control-structures.ht
ml#PLPGSQL-RECORDS-ITERATING

HTH

Adam

> hello,
>
> it is possible to write something similar???
>
> create function get_count(varchar(32)) RETURNS int4 AS '
> DECLARE
> tmp int4;
> BEGIN
> SELECT COUNT(*) INTO tmp FROM $1;
> RETURN tmp;
> END;' LANGUAGE 'plpgsql';
>
>
> SELECT get_count('k_part');
> SQL error:
> ERROR: parser: parse error at or near "$1" at character 24
>
> thanx, miso
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Grant Rutherford 2003-10-27 16:30:41 PostgreSQL with MS Query?
Previous Message Chris M. Gamble 2003-10-27 16:10:02 Replication again