pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kyle Bateman <kyle@actarg.com>
To: Stef telford <stef@chronozon.dyndns.org>
Cc: pgsql-sql@postgresql.org
Subject: Clarified Question
Date: Wed, 24 May 2000 16:44:44 -0600
Message-ID: <392C5B5C.64CCAA78@actarg.com> (raw)
References: <200005242202.SAA71408@hub.org>

>
> 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';

Attachments:

kyle.vcf (text/x-vcard, 290B) download begin:vcard n:Bateman;Kyle tel;fax:801-377-8096 tel;work:801-377-8033x101 x-mozilla-html:FALSE url:www.actiontarget.com org:Action Target Inc adr:;;PO Box 636;Provo;UT;84603;US version:2.1 email;internet:kyle@actiontarget.com title:President x-mozilla-cpt:;-15520 fn:Kyle Bateman end:vcard

view thread (2+ messages)

Message-ID: <392C5B5C.64CCAA78@actarg.com>
Permalink:  ../392C5B5C.64CCAA78@actarg.com/
Also on:    postgresql.org/message-id/392C5B5C.64CCAA78@actarg.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: kyle@actarg.com, stef@chronozon.dyndns.org
  Subject: Re: Clarified Question
  In-Reply-To: <392C5B5C.64CCAA78@actarg.com>
  References: <200005242202.SAA71408@hub.org> <392C5B5C.64CCAA78@actarg.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox