PL/PGSQL - How to pass in variables?

Поиск
Список
Период
Сортировка
От Scott Yohonn
Тема PL/PGSQL - How to pass in variables?
Дата
Msg-id ff1df1410605140828s2ac7c170j9d7c4e5b2b0a1f5c@mail.gmail.com
обсуждение исходный текст
Ответы Re: PL/PGSQL - How to pass in variables?  (Jean-Paul Argudo <jean-paul@argudo.org>)
Re: PL/PGSQL - How to pass in variables?  ("Jaime Casanova" <systemguards@gmail.com>)
Список pgsql-sql
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;
     
     RETURN rowcount;
     
   END;
 $$ LANGUAGE 'plpgsql';
 

В списке pgsql-sql по дате отправления:

Предыдущее
От: Emi Lu
Дата:
Сообщение: Re: R: Re: R: R: Re: schema inspection
Следующее
От: Jean-Paul Argudo
Дата:
Сообщение: Re: PL/PGSQL - How to pass in variables?