Re: Query is fast and function is slow - Mailing list pgsql-sql

From Thomas Pundt
Subject Re: Query is fast and function is slow
Date
Msg-id 200612071641.27686.mlists@rp-online.de
Whole thread Raw
In response to Re: Query is fast and function is slow  (Richard Ray <rray@mstc.state.ms.us>)
List pgsql-sql
Hi,

On Thursday 07 December 2006 15:53, Richard Ray wrote:
| But this same statement in a function takes several minutes;
|
| My SQL knowledge is pitiful so would you explain how to use
| "explain analyze" in the function
|
| I get errors when I try to load the file with
| raise notice  ''%'',explain analyze select doc_num from documents where
| doc_num = doc_number;
|
| dcc=# \i
| /src/check_for_update_permission
| psql:/src/check_for_update_permission:52:
| ERROR:  syntax error at or near "analyze" at character 16
| QUERY:  SELECT explain analyze select doc_num from documents where doc_num
| =  $1
| CONTEXT:  SQL statement in PL/PgSQL function "check_for_update_permission"
| near line 18
| psql:/src/check_for_update_permission:52:
| LINE 1: SELECT explain analyze select doc_num from documents where d...
| psql:/src/check_for_update_permission:52:
| ^
| dcc=#

ok, seems you can't use a SQL statement as expression here; instead try
using a "for statement" then:
 for v_rec in explain analyze <your_query_here> loop     raise notice '%', v_rec; end loop;

don't forget to declare "v_rec text;"

Ciao,
Thomas

-- 
Thomas Pundt <thomas.pundt@rp-online.de> ---- http://rp-online.de/ ----


pgsql-sql by date:

Previous
From: Richard Ray
Date:
Subject: Re: Query is fast and function is slow
Next
From: Tom Lane
Date:
Subject: Re: Query is fast and function is slow