pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Clarified Question
2+ messages / 2 participants
[nested] [flat]

* Clarified Question
@ 2000-05-24 01:36  Stef telford <stef@chronozon.dyndns.org>
  0 siblings, 0 replies; 2+ messages in thread

From: stef@chronozon.dyndns.org @ 2000-05-24 01:36 UTC (permalink / raw)
  To: pgsql-sql

Hello,
	Earlier I sent in some ramblings trying to explain my problm.
I think I have it better summarised now.

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;'
		
Please excuse the roughness of the code, I am not at my work machine
where I have postgres all setup. 

(oh. and jst a little query, is the 'max' actaully a stored procedure
 or an SQL keyword ?! I cant seem to find it in any of the documentation
 probbly cause I overlooked it ;)

Thanks,
Steffs



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Clarified Question
@ 2000-05-24 22:44  Kyle Bateman <kyle@actarg.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Kyle Bateman @ 2000-05-24 22:44 UTC (permalink / raw)
  To: Stef telford <stef@chronozon.dyndns.org>; +Cc: 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';

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
^ permalink raw reply [nested|flat] 2+ messages in thread


end of thread, other threads:[~2000-05-24 22:44 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-05-24 01:36 Clarified Question Stef telford <stef@chronozon.dyndns.org>
2000-05-24 22:44 Clarified Question Kyle Bateman <kyle@actarg.com>

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