Re: [SQL] returning values from dynamic SQL to a variable

2013-01-15 Thread Karl Grossner
Pavel - RETURN QUERY EXECUTE worked, many thanks for responding so quickly. The docs show no relevant examples, so for anyone else, something like this create or replace function getRowsE( OUT element character(1), OUT name character varying(100), OUT sum numeric ) returns setof record a

Re: [SQL] Curious problem of using BETWEEN with start and end being the same versus EQUALS '='

2013-01-15 Thread Venky Kandaswamy
Thanks for the quick and detailed response, Tom. Yes, I did add a redundant where clause with a restriction on b.date_id on the range queries. This appears to speed things up since it does an index scan on the b table before the merge join. We will get more intelligent on query generation (ou

Re: [SQL] Curious problem of using BETWEEN with start and end being the same versus EQUALS '='

2013-01-15 Thread Tom Lane
Venky Kandaswamy writes: >On 9.1, I am running into a curious issue. It's not very curious at all, or at least people on pgsql-performance (the right list for this sort of question) would have figured it out quickly. You're getting a crummy plan because of a crummy row estimate. When you do

Re: [SQL] returning values from dynamic SQL to a variable

2013-01-15 Thread Pavel Stehule
Hello you can use RETURN QUERY EXECUTE statement http://www.postgresql.org/docs/9.1/interactive/plpgsql-control-structures.html#PLPGSQL-STATEMENTS-RETURNING Regards Pavel Stehule 2013/1/15 kgeographer : > I have a related problem and tried the PERFORM...EXECUTE pattern suggested > but no matte

[SQL] Curious problem of using BETWEEN with start and end being the same versus EQUALS '='

2013-01-15 Thread Venky Kandaswamy
All, On 9.1, I am running into a curious issue. I will explain the issue in high level terms using psuedo SQL statements. Consider a SQL statement: SELECT a, b, c FROM tab WHERE a = value1; - This does an index scan followed by a merge join and takes about 37 secs to execute If I change the

Re: [SQL] returning values from dynamic SQL to a variable

2013-01-15 Thread kgeographer
I have a related problem and tried the PERFORM...EXECUTE pattern suggested but no matter where I put PERFORM I get 'function not found' errors. I want to loop through id values returned by a query and execute another with each i as a parameter. Each subquery will return 6-8 rows. This is a simplif

Re: [SQL] Why doesn't this work

2013-01-15 Thread Rob Sargent
On 01/15/2013 04:50 AM, Barbara Woolums wrote: I am running a query like so SELECT id FROM image WHERE image='demo-harvey wallbanger.jpg' It returns nothing My table looks like this "demo-820.jpg";1 "demo-lemon-mousse-1.jpg";2 "demo-pumpkinchaibars.jpg";3 "demo-Lolly-Shop.jpg";4 "demo-scan000

Re: [SQL] Why doesn't this work

2013-01-15 Thread Leif Biberg Kristensen
Tirsdag 15. januar 2013 12.50.00 skrev Barbara Woolums : > I am running a query like so > > SELECT id FROM image WHERE image='demo-harvey wallbanger.jpg' > > It returns nothing > > My table looks like this > > "demo-820.jpg";1 > "demo-lemon-mousse-1.jpg";2 > "demo-pumpkinchaibars.jpg";3 > "dem

Re: [SQL] Why doesn't this work

2013-01-15 Thread Bèrto ëd Sèra
Hi Barbara, from what I see in your msg, you have a /cr at the end of the filename. You should check for weird stuff and trim it away (before insert triggers do wonders at this). Cheers Bèrto On 15 January 2013 11:50, Barbara Woolums wrote: > I am running a query like so > > SELECT id FROM imag

[SQL] Why doesn't this work

2013-01-15 Thread Barbara Woolums
I am running a query like so SELECT id FROM image WHERE image='demo-harvey wallbanger.jpg' It returns nothing My table looks like this "demo-820.jpg";1 "demo-lemon-mousse-1.jpg";2 "demo-pumpkinchaibars.jpg";3 "demo-Lolly-Shop.jpg";4 "demo-scan0001.jpg";5 "demo-cherry-chocolate-mousse-pie.jpg";6