Clarified Question - Mailing list pgsql-sql

From Kyle Bateman
Subject Clarified Question
Date
Msg-id 392C5B5C.64CCAA78@actarg.com
Whole thread Raw
List pgsql-sql
 
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';
 

Attachment

pgsql-sql by date:

Previous
From: Joseph Shraibman
Date:
Subject: possible bug with group by?
Next
From: JanWieck@t-online.de (Jan Wieck)
Date:
Subject: Re: Why is PostgreSQL 7.0 SQL semantics different from Oracle's?