Olá, Sérgio

Segue um exemplo de como você poderia fazer:

CREATE OR REPLACE FUNCTION exemplo_tabela(nome_da_tabela text)
RETURNS integer AS $$
DECLARE
  var_cursor refcursor;
  numero_de_linhas integer not null:=0;
BEGIN
  OPEN var_cursor FOR EXECUTE ' SELECT count(*) FROM ' || nome_da_tabela;
  FETCH var_cursor INTO numero_de_linhas;
  RETURN numero_de_linhas;
END;
$$ LANGUAGE PLPGSQL;


2009/6/22 sergio nogueira <[email protected]>

> É possível usar o nome de uma tabela como parâmetro de uma função?
> Isto não funciona.
>
>   create function xx (tabela varchar) returns integer as $$
>    declare intx integer;
>     begin
>       select into intx count(*) from $1;
>       return intx;
>     end
>   $$ language plpgsql;
>
> Att.,
> Sergio
>
> _______________________________________________
> pgbr-geral mailing list
> [email protected]
> https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral
>
>

[]s
-- 
JotaComm
http://jotacomm.wordpress.com
http://www.dextra.com.br/postgres
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a