Re: Query is fast and function is slow

Поиск
Список
Период
Сортировка
От Thomas Pundt
Тема Re: Query is fast and function is slow
Дата
Msg-id 200612071641.27686.mlists@rp-online.de
обсуждение исходный текст
Ответ на Re: Query is fast and function is slow  (Richard Ray <rray@mstc.state.ms.us>)
Список 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 по дате отправления:

Предыдущее
От: Richard Ray
Дата:
Сообщение: Re: Query is fast and function is slow
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Query is fast and function is slow