Error passing parameter to functions

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

Error passing parameter to functions

От:
"Jose Luis LG" <jlopezgonz@terra.es>
Дата:

HI,

 

Could someone tell me what I am doing wrong please (Postgresql 7.2).  Thanks

 

 

The functions I am creating is:

 

 

   CREATE OR REPLACE FUNCTION getthemedescription (text) RETURNS text AS '

   DECLARE

      themeid ALIAS FOR $1;

      metaid metadata.meta_id%TYPE;

      generalid general.general_id%TYPE;

      descriptionidcursor CURSOR FOR SELECT description_id FROM general_description WHERE general_id = generalid;

 

   BEGIN

      SELECT INTO metaid meta_id FROM themehasmetadata WHERE theme_id =  themeid;

      SELECT INTO generalid general_id FROM meta_general WHERE meta_id = metaid;

      OPEN descriptionidcursor;

 

      RETURN "descriptionidcursor"

END;

' LANGUAGE 'plpgsql';

 

 

I call this function in the following way:

 

 

      String themeID = "mathematics";

      String queryString = "SELECT getthemedescription(" + themeID + ")");

 

      Statement stmt = conn.createStatement();

 

      ResultSet l_cursorRSet = stmt.executeQuery(queryString);

 

                        .......

 

If I send the themeID as above I get: ERROR: Attribute 'mathematics' not found.

 

If I send the themeID = "'mathematics'" I get:  fmgr_info: function

24907: cache lookup failed.

 

I think it has something to do with the quotes, but what?

 

 

Best regards

 

 

Jose Luis

 

Re: Error passing parameter to functions

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"Jose Luis LG"  writes:
> If I send the themeID as above I get: ERROR: Attribute 'mathematics' not
> found.

As expected.
> If I send the themeID = "'mathematics'" I get:  fmgr_info: function
> 24907: cache lookup failed.

The query syntax is now correct, but there's something broken about your
function definition.  My bet is that the plpgsql call handler function
has been deleted.  Try reinstalling plpgsql --- ie, rerun createlang;
and then recreate your function, since it'll still be pointing at the
old plpgsql OID.
		regards, tom lane

Re: Error passing parameter to functions

От:
"Jose Luis LG" <jlopezgonz@terra.es>
Дата:
Thanks a lot Tom,

This was exactly the problem.  I was going crazy thinking it was an
error in my code.  Is this a bug in postgresql?


Best regards


Jose Luis

> -----Original Message-----
> From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
> Sent: martes, 05 de marzo de 2002 17:04
> To: Jose Luis LG
> Cc: pgsql-interfaces@postgresql.org
> Subject: Re: [INTERFACES] Error passing parameter to functions
> 
> "Jose Luis LG"  writes:
> > If I send the themeID as above I get: ERROR: Attribute 'mathematics'
not
> > found.
> 
> As expected.
> 
> > If I send the themeID = "'mathematics'" I get:  fmgr_info: function
> > 24907: cache lookup failed.
> 
> The query syntax is now correct, but there's something broken about
your
> function definition.  My bet is that the plpgsql call handler function
> has been deleted.  Try reinstalling plpgsql --- ie, rerun createlang;
> and then recreate your function, since it'll still be pointing at the
> old plpgsql OID.
> 
> 			regards, tom lane


Re: Error passing parameter to functions

От:
"Jose Luis LG" <jlopezgonz@terra.es>
Дата:
Thanks a lot Tom,

This was exactly the problem.  I was going crazy thinking it was an
error in my code.  Is this a bug in postgresql?


Best regards


Jose Luis

> -----Original Message-----
> From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
> Sent: martes, 05 de marzo de 2002 17:04
> To: Jose Luis LG
> Cc: pgsql-interfaces@postgresql.org
> Subject: Re: [INTERFACES] Error passing parameter to functions
> 
> "Jose Luis LG"  writes:
> > If I send the themeID as above I get: ERROR: Attribute 'mathematics'
not
> > found.
> 
> As expected.
> 
> > If I send the themeID = "'mathematics'" I get:  fmgr_info: function
> > 24907: cache lookup failed.
> 
> The query syntax is now correct, but there's something broken about
your
> function definition.  My bet is that the plpgsql call handler function
> has been deleted.  Try reinstalling plpgsql --- ie, rerun createlang;
> and then recreate your function, since it'll still be pointing at the
> old plpgsql OID.
> 
> 			regards, tom lane


FAQ