[SQL] Can someone explain the problem with this select

2006-12-05 Thread Richard Ray
Allow me to demonstrate my pitiful SQL knowledge I have tables documents and comments If I run join and list doc_nums the query is quite fast If I run join and use subselect the query is extremely slow Can someone offer analysis Thanks Richard dcc=# EXPLAIN ANALYZE select doc_num from documents

Re: [SQL] Can someone explain the problem with this select

2006-12-05 Thread Richard Ray
I've been foolin with this for a couple of days Sometimes you just have to ask Thanks gentlemen On Tue, 5 Dec 2006, Tom Lane wrote: Richard Ray <[EMAIL PROTECTED]> writes: dcc=# EXPLAIN ANALYZE select * from documents left outer join comments on (documents.doc_num = comments.doc

[SQL] Query is fast and function is slow

2006-12-06 Thread Richard Ray
The query 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 (groname ~ '.*owner$' or groname = 'admin'))) & access > '0

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 whe

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? Actua

[SQL] Help with quotes in plpgsql

2006-12-19 Thread Richard Ray
How should this be properly quoted create or replace function test(integer) returns setof text as $$ declare a record; begin select into a now() - interval '$1 day'; return next a; return; end $$ language 'plpgsql'; I'm not having a lot of luck Thanks Richard ---

Re: [SQL] Help with quotes in plpgsql

2006-12-19 Thread Richard Ray
;days')::interval; return next a; return; end $$ language 'plpgsql'; This works quite well I never looked at it that way Thanks -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Richard Ray Sent: Tuesday, December 19, 2006 12

Re: [SQL] Help with quotes in plpgsql

2006-12-19 Thread Richard Ray
On Tue, 19 Dec 2006, Milen A. Radev wrote: Richard Ray : How should this be properly quoted create or replace function test(integer) returns setof text as $$ declare a record; begin select into a now() - interval '$1 day'; return next a; return; end $$ languag

Re: [SQL] Help with quotes in plpgsql

2006-12-20 Thread Richard Ray
It makes sense when ya'll explain it It never sounds that good when I'm talkin to myself That solves my problem but not my ignorance I'm still curious about how would I properly quote create or replace function test(integer) returns setof text as $$ declare a record; begin select into a now()

[SQL] How to query by column names

2007-01-22 Thread Richard Ray
This may be a simple but can I create a query such as select (select attname from pg_attribute where attrelid = (select relfilenode from pg_class where relname = 't1') and attisdropped = false and attnum > 0) from t1; I get ERROR: more than one row returned by a subquery used as an expressio

Re: [SQL] How to query by column names

2007-01-22 Thread Richard Ray
ropped IS FALSE AND pa.attnum > 0; Let me know if it doesn't do what you intended. On Mon, 22 Jan 2007, Richard Ray wrote: This may be a simple but can I create a query such as select (select attname from pg_attribute where attrelid = (select relfilenode from pg_class wh

Re: [SQL] How to query by column names

2007-01-22 Thread Richard Ray
arlier. What information are you trying to extract? On Mon, 22 Jan 2007, Richard Ray wrote: This is not exactly what I need I want to return the data in t1 On Mon, 22 Jan 2007, Jeff Frost wrote: I think this is what you're looking for Richard: SELECT attname FROM pg_attribute pa, pg_class pc

Re: [SQL] How to query by column names

2007-01-22 Thread Richard Ray
On Mon, 22 Jan 2007, Jeff Frost wrote: So why are you avoiding "SELECT * FROM t1;" ? I was affeared that if I brought my total ignorance to light I would be band from the list but here goes. I work in UNIX/Linux environments. It's my habit to record my scripts. A simple example: #!/bin/bash

[SQL] How to influence the planner

2007-08-31 Thread Richard Ray
about 20 minutes My simple solution is "select * into t2 from t1 where length(bar) = 0;" and "select * from t2 order by foo ;" Is there a way to make "select * from t1 where length(bar) = 0 order by foo ;" or something similar work Thanks Richard

Re: [SQL] How to influence the planner

2007-08-31 Thread Richard Ray
On Fri, 31 Aug 2007, Michael Glaesemann wrote: On Aug 31, 2007, at 13:32 , Richard Ray wrote: "select * from t1 where length(bar) = 0;" runs about 2 minutes "select * from t1 where length(bar) = 0 order by foo ;" ran until I stopped it after about 20 minutes EXPLAIN A

Re: [SQL] How to influence the planner

2007-08-31 Thread Richard Ray
On Fri, 31 Aug 2007, Tom Lane wrote: Richard Ray <[EMAIL PROTECTED]> writes: On Fri, 31 Aug 2007, Michael Glaesemann wrote: EXPLAIN ANALYZE will help you see what the planner is doing to produce the results. mda=# EXPLAIN ANALYZE select * from t1 where length(bar) = 0 order

Re: [SQL] How to influence the planner

2007-09-04 Thread Richard Ray
Thanks guys Lesson learned On Tue, 4 Sep 2007, Scott Marlowe wrote: On 8/31/07, Richard Ray <[EMAIL PROTECTED]> wrote: Changing to enable_seqscan = on does solve this problem, thanks Is there some method of crafting a query that will assert my wishes to the planner When is enable_s