Re: Argument variables for select - Mailing list pgsql-sql

From Andreas Tille
Subject Re: Argument variables for select
Date
Msg-id Pine.LNX.4.21.0008291403150.7758-100000@wr-linux02.rki.de
Whole thread Raw
In response to Re: Argument variables for select  (Yury Don <yura@vpcit.ru>)
Responses Re: Re: Argument variables for select  (Keith Wong <keith@e-magine.com.au>)
List pgsql-sql
On Mon, 28 Aug 2000, Yury Don wrote:

> > Create Function VarSelect ( varchar, varchar )
> >    returns int
> >    As '
> >      Declare num int ;
> > 
> >      Begin
> >        Select Into num Count(*) From $1 Where $2 ;
> >        return num;
> >      End ;
> >    ' language 'plpgsql' ;
> > 
> > Could someone please explain who to type the exact syntax so that
> > I can ship the table to select from as $1 and the condition to select
> > what as $2?  Or do I have to concatenate a string with the whole
> > select statement and how to call this string?  In MS SQL server this
> > could be done with
> >    Exec ( query )
> > 
> AFAIK it's impossible with plpgsql, but it's possible in pltcl.

It is really hard to believe that I'm in so very deep trouble with
PostgreSQL.  It seems to me that stored procedures are far from beeing
as usefull as I learned them to know in MS SQL server.  Once I try
to follow one hint I'm standing in frot of the next even harder problem.


web=# create function testfunc( )
web-#   returns int
web-#   As '
web'#       spi_exec "SELECT count(*) AS $num FROM testtable"
web'# 
web'#       return $num ;
web'#     End; '
web-#   language 'pltcl' ;
ERROR:  Unrecognized language specified in a CREATE FUNCTION: 'pltcl'.  Recognized languages are sql, C, internal and
thecreated procedural languages.
 


I have installed the pgtcl package of my Debian distribution, so I guess
it should be available.  Once more the question:  Is it really necessary to
use a further interpreter instead of sticking with SQL commands to use
the original problem.

I have to admit that my boss wonders why I'm switching from a working
solution (MS SQL) to so much trouble :-(.  I really hope to convince him
to OpenSource but it's much harder than I expected.

Kind regards
         Andreas.



pgsql-sql by date:

Previous
From: "Craig Manley"
Date:
Subject: How do you detect row version changes in PostgreSQL?
Next
From: Jerome Raupach
Date:
Subject: performance on insert/update