creating a function with a variable table name
От | George Nychis |
---|---|
Тема | creating a function with a variable table name |
Дата | |
Msg-id | 45E6FCAA.7020107@cmu.edu обсуждение исходный текст |
Ответы |
Re: creating a function with a variable table name
Re: creating a function with a variable table name |
Список | pgsql-general |
Hey all, I'm trying to create a function in which the table a query is run on is variable, but I guess this is not as easy as I thought. BEGIN dp=> CREATE FUNCTION stats_addr_dst(date,text) dp-> RETURNS setof addr_count dp-> AS 'SELECT ip,sum(dst_packets) dp'> FROM( dp'> (SELECT dst_ip AS ip,sum(src_packets) AS dst_packets dp'> FROM $2 dp'> WHERE interval=$1 dp'> GROUP BY dst_ip) dp'> UNION ALL dp'> (SELECT src_ip AS ip,sum(dst_packets) AS dst_packets dp'> FROM $2 dp'> WHERE interval=$1 dp'> GROUP BY src_ip) ) dp'> AS topk dp'> GROUP BY topk.ip dp'> HAVING sum(dst_packets)>0 dp'> ORDER BY sum(dst_packets) DESC;' dp-> LANGUAGE SQL; ERROR: syntax error at or near "$2" at character 179 LINE 6: FROM $2 ^ How can I pass the table name? Thanks! George
В списке pgsql-general по дате отправления: