Обсуждение: Clarified Question

Поиск
Список
Период
Сортировка

Clarified Question

От
Kyle Bateman
Дата:
 
How can I create a function that will take in two variables and return
an integer, when one of the variables is the tablename ?!

I have tried :

                create function tst_func(text, varchar(16))
                as
                'BEGIN
                        result=select max(history_id)+1 from $1
                                where client_id = $2;
                        return result;
                 END;'
 

This kind of thing does work in pltcl but AFAIK you can't specify a table name with a parameter in plpgsql.  This may give you the idea:

create function myfunc(text,text) returns result as '
    set res [spi_exec "select f1 from $1 where f2 = \'$2\']
    return $res
    ' language 'pltcl';
 

Вложения