Re: [SQL] Query is fast and function is slow

2006-12-07 Thread Tom Lane
Richard Ray <[EMAIL PROTECTED]> writes: > Changing both parameters to char(9) and name fixed the problem > It appears to be using the index > If time allows could you explain this a bit EXPLAIN will show you what's going on: regression=# create table foo (f1 char(9) unique); NOTICE: CREATE TABLE

Re: [SQL] Query is fast and function is slow

2006-12-07 Thread Richard Ray
On Thu, 7 Dec 2006, Tom Lane wrote: Richard Ray <[EMAIL PROTECTED]> writes: On Thu, 7 Dec 2006, Thomas Pundt wrote: Just a guess: is the column "doc_num" really of type text? Maybe using "text" in the function lets the planner choose a sequential scan? Actually "doc_num" is char(9) I change

Re: [SQL] Query is fast and function is slow

2006-12-07 Thread Tom Lane
Richard Ray <[EMAIL PROTECTED]> writes: > On Thu, 7 Dec 2006, Thomas Pundt wrote: >> Just a guess: is the column "doc_num" really of type text? Maybe using "text" >> in the function lets the planner choose a sequential scan? > Actually "doc_num" is char(9) > I changed text to char(9) and got same

Re: [SQL] Query is fast and function is slow

2006-12-07 Thread Thomas Pundt
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 ''%'',expl

Re: [SQL] Query is fast and function is slow

2006-12-07 Thread Richard Ray
On Thu, 7 Dec 2006, Thomas Pundt wrote: Hi, On Wednesday 06 December 2006 16:44, Richard Ray wrote: | select count(*) from documents where doc_num = '106973821' and (select | bit_or(group_access) from mda_groups where group_name in (select groname | from pg_user,pg_group where usename = 'bbob

Re: [SQL] Query is fast and function is slow

2006-12-07 Thread Thomas Pundt
Hi, On Wednesday 06 December 2006 16:44, Richard Ray wrote: | select count(*) from documents where doc_num = '106973821' and (select | bit_or(group_access) from mda_groups where group_name in (select groname | from pg_user,pg_group where usename = 'bbob' and usesysid = any(grolist) | and (grona