Unix Technical Forum

function body error checking issues

This is a discussion on function body error checking issues within the Pgsql General forums, part of the PostgreSQL category; --> Bruce, here is a example: (there is a simple error in the function that does not get caught when ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 07:44 PM
tony_caduto@amsoftwaredesign.com
 
Posts: n/a
Default function body error checking issues

Bruce,
here is a example:
(there is a simple error in the function that does not get caught when running the query in 8.0)

CREATE or REPLACE FUNCTION annual.get_ratio( float8, float8)
RETURNS pg_catalog.float8 AS
$BODY$
DECLARE
execptioncount_in alias for $1;
questioncount_in alias for $2;
ratio_out float8;

BEGIN
IF (execptioncount_in >0) AND (questioncount_in >0) THEN

RATIO_OUT = execptioncount_in / questioncount_in;

ELSE
--this variable is not declared, yet when I run this query no error is raised
EXCEPTIONRATIO_OUT = 0;
END IF;
return ratio_out;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;

>
> From: Bruce Momjian <pgman@candle.pha.pa.us>
> Date: 2005/02/21 Mon AM 10:47:35 EST
> To: tony_caduto@amsoftwaredesign.com
> CC: pgsql-general@postgresql.org
> Subject: Re: [GENERAL] is there anyway to get the backends IP address from
>
> Tony Caduto wrote:
> > Bruce,
> > On another note, is there plans to improve the type checking of stored
> > functions during the save/compile?
> > Currently I can pretty much make tons of mistakes (on purpose of course
> > :-) and they are not flagged as errors until runtime.
> > The biggest complaint I see from other DBAs (MS SQL, Oracle) is that
> > Postgres does little to no pre-runtime type checking.

>
> We have no plans to improve that. We do have 'check_function_bodies'
> which defaults to true and does some checking. Would you give us a
> particular example you would like improved?
>
> --
> Bruce Momjian | http://candle.pha.pa.us
> pgman@candle.pha.pa.us | (610) 359-1001
> + If your life is a hard drive, | 13 Roberts Road
> + Christ can be your backup. | Newtown Square, Pennsylvania 19073
>



---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 07:46 PM
Bruce Momjian
 
Posts: n/a
Default Re: function body error checking issues

tony_caduto@amsoftwaredesign.com wrote:
> Bruce,
> here is a example:
> (there is a simple error in the function that does not get caught when running the query in 8.0)
>
> CREATE or REPLACE FUNCTION annual.get_ratio( float8, float8)
> RETURNS pg_catalog.float8 AS
> $BODY$
> DECLARE
> execptioncount_in alias for $1;
> questioncount_in alias for $2;
> ratio_out float8;
>
> BEGIN
> IF (execptioncount_in >0) AND (questioncount_in >0) THEN
>
> RATIO_OUT = execptioncount_in / questioncount_in;
>
> ELSE
> --this variable is not declared, yet when I run this query no error is raised
> EXCEPTIONRATIO_OUT = 0;
> END IF;
> return ratio_out;
> END;
> $BODY$
> LANGUAGE 'plpgsql' VOLATILE


Syntax error reporting has been improved in our code so 8.1 might be
better and catching such errors.

--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 07:48 PM
Neil Conway
 
Posts: n/a
Default Re: function body error checking issues

Bruce Momjian wrote:
> Syntax error reporting has been improved in our code so 8.1 might be
> better and catching such errors.


Yes, current sources catches this at definition-time:

% psql -f test.sql
psql:test.sql:21: ERROR: syntax error at or near "EXCEPTIONRATIO_OUT"
at character 1
QUERY: EXCEPTIONRATIO_OUT = 0
CONTEXT: SQL statement in PL/PgSQL function "get_ratio" near line 13
psql:test.sql:21: LINE 1: EXCEPTIONRATIO_OUT = 0
psql:test.sql:21: ^

If folks have more suggestions for improving pl/pgsql compile-time error
checking, speak up. I'm also planning to implement trivially-dead-code
detection (like statements that follow a RETURN, and so on), although
that's not in HEAD yet.

-Neil

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:30 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com