Re: Pass in variable from user???

Поиск
Список
Период
Сортировка
Искать
От
A. Kretschmer
Тема
Re: Pass in variable from user???
Дата
в 10:03:42
Msg-id
20060515130311.GD24724@webserv.wug-glas.de
Ответ на
Pass in variable from user??? (syohonn@gmail.com)
Список
Дерево обсуждения
Pass in variable from user??? "syohonn@gmail.com" <syohonn@gmail.com>
Re: Pass in variable from user??? "A. Kretschmer" <andreas.kretschmer@schollglas.com>
Re: Pass in variable from user??? "Michael Artz" <mlartz@gmail.com>
am  13.05.2006, um 14:15:52 -0700 mailte syohonn@gmail.com folgendes:
> Using PL/PGSQL, I am trying to create a procedure to display the count
> of rows in any single table of a database. The End-user would pass in a
> table name and the prodecure would display the table name with the row
> count.
> I am able to hardcode the variable for table and get the appropriate
> results from my count function (see below), but cannot pass in a
> variable and have the function work. Any suggesstions???
> 
> CREATE FUNCTION get_table_count(tablename text) RETURNS integer AS $$
>   DECLARE
> 
>     --tablename ALIAS FOR $1;
> 
>      rowcount INTEGER;
>   BEGIN
> 
>     SELECT INTO rowcount count(*) FROM tablename;

You can't do SL direct with such parameters, but you can use
EXECUTE. Please read:

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


HTH, Andreas
-- 
Andreas Kretschmer    (Kontakt: siehe Header)
Heynitz:  035242/47215,      D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
 ===    Schollglas Unternehmensgruppe    === 
В списке pgsql-general по дате отправления
От: Martijn van Oosterhout
Дата:
От: Michael Artz
Дата:
FAQ