Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id B6A799FA1DA for ; Thu, 7 Dec 2006 11:40:07 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 83580-05 for ; Thu, 7 Dec 2006 11:40:06 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mail.rp-online.de (mail.rp-online.de [149.221.1.199]) by postgresql.org (Postfix) with ESMTP id 4D8869FA0B7 for ; Thu, 7 Dec 2006 11:40:07 -0400 (AST) Received: from idefix.d.rp-online.de (idefix.d.rp-online.de [149.221.100.194]) by mail.rp-online.de (Postfix) with ESMTP id 950102EDD4; Thu, 7 Dec 2006 16:40:05 +0100 (CET) From: Thomas Pundt Reply-To: Thomas Pundt Organization: RP Online GmbH To: pgsql-sql@postgresql.org, Richard Ray Subject: Re: Query is fast and function is slow Date: Thu, 7 Dec 2006 16:41:27 +0100 User-Agent: KMail/1.9.4 References: <200612071053.01287.mlists@rp-online.de> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200612071641.27686.mlists@rp-online.de> X-Anti-Virus: Kaspersky Anti-Virus for MailServers 5.5.10/RELEASE, bases: 07122006 #234837, status: clean X-Archive-Number: 200612/75 X-Sequence-Number: 27031 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 loop raise notice '%', v_rec; end loop; don't forget to declare "v_rec text;" Ciao, Thomas -- Thomas Pundt ---- http://rp-online.de/ ----