pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedLIMIT problem
5+ messages / 3 participants
[nested] [flat]
* LIMIT problem
@ 2010-04-30 12:50 silly sad <sad@bankir.ru>
0 siblings, 2 replies; 5+ messages in thread
From: silly sad @ 2010-04-30 12:50 UTC (permalink / raw)
To: pgsql-sql
suppose i request
SELECT foo(t.x) FROM t LIMIT 1;
Whither it DEFINED how many times foo() will be executed?
May anyone rely on it?
Or we have to avoid this non SQLish trick?
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: LIMIT problem
@ 2010-04-30 12:57 Nilesh Govindarajan <lists@itech7.com>
parent: silly sad <sad@bankir.ru>
1 sibling, 1 reply; 5+ messages in thread
From: Nilesh Govindarajan @ 2010-04-30 12:57 UTC (permalink / raw)
To: pgsql-sql
On 04/30/2010 06:20 PM, silly sad wrote:
> suppose i request
>
> SELECT foo(t.x) FROM t LIMIT 1;
>
> Whither it DEFINED how many times foo() will be executed?
>
> May anyone rely on it?
> Or we have to avoid this non SQLish trick?
>
It will execute foo only once, and give only one row out of the n rows
it returns. If I'm wrong please correct me.
--
Nilesh Govindarajan
Site & Server Administrator
www.itech7.com
मेरा भारत महान !
मम भारत: महत्तम भवतु !
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: LIMIT problem
@ 2010-04-30 23:58 Jasen Betts <jasen@xnet.co.nz>
parent: silly sad <sad@bankir.ru>
1 sibling, 1 reply; 5+ messages in thread
From: Jasen Betts @ 2010-04-30 23:58 UTC (permalink / raw)
To: pgsql-sql
On 2010-04-30, silly sad <sad@bankir.ru> wrote:
> suppose i request
>
> SELECT foo(t.x) FROM t LIMIT 1;
>
> Whither it DEFINED how many times foo() will be executed?
foo will be executed repeatedly until it returns a result or all the
rows in t are exhausted.
> May anyone rely on it?
not sure
> Or we have to avoid this non SQLish trick?
This will execute it once (or not at all where t has no rows)
SELECT foo(x) FROM (SELECT x FROM t LIMIT 1) as bar;
But may return a number of records differing from 1 in the case where
foo is a set-returning function.
jasen=# select a from foo;
a
---
1
4
7
6
3
6 rows)
jasen=# select generate_series(1,a),a from foo limit 1;
generate_series | a
-----------------+---
1 | 1
(1 row)
the first row jas 1 and the first row from
generate_series(1,1) is returned
jasen=# select generate_series(5,a),a from foo limit 1;
generate_series | a
-----------------+---
5 | 7
(1 row)
the 1st row has 1 and generate_series(5,1) returns 0 rows
the 2nd row has 4 and generate_series(5,4) returns 0 rows
the 3rd row has 7 and generate_series(5,7) returns 3 rows
And the first of those is returned.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: LIMIT problem
@ 2010-05-01 08:55 silly sad <sad@bankir.ru>
parent: Nilesh Govindarajan <lists@itech7.com>
0 siblings, 0 replies; 5+ messages in thread
From: silly sad @ 2010-05-01 08:55 UTC (permalink / raw)
To: pgsql-sql
On 04/30/10 16:57, Nilesh Govindarajan wrote:
> On 04/30/2010 06:20 PM, silly sad wrote:
>> suppose i request
>>
>> SELECT foo(t.x) FROM t LIMIT 1;
>>
>> Whither it DEFINED how many times foo() will be executed?
>>
>> May anyone rely on it?
>> Or we have to avoid this non SQLish trick?
>>
>
> It will execute foo only once, and give only one row out of the n rows
> it returns. If I'm wrong please correct me.
I did not asked how many times foo() would be executed.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: LIMIT problem
@ 2010-05-01 09:05 silly sad <sad@bankir.ru>
parent: Jasen Betts <jasen@xnet.co.nz>
0 siblings, 0 replies; 5+ messages in thread
From: silly sad @ 2010-05-01 09:05 UTC (permalink / raw)
To: pgsql-sql
On 05/01/10 03:58, Jasen Betts wrote:
> On 2010-04-30, silly sad<sad@bankir.ru> wrote:
>> suppose i request
>>
>> SELECT foo(t.x) FROM t LIMIT 1;
>>
>> Whither it DEFINED how many times foo() will be executed?
>
> foo will be executed repeatedly until it returns a result or all the
> rows in t are exhausted.
>
>> May anyone rely on it?
>
> not sure
>
>> Or we have to avoid this non SQLish trick?
>
>
> This will execute it once (or not at all where t has no rows)
>
> SELECT foo(x) FROM (SELECT x FROM t LIMIT 1) as bar;
>
this subselect "isolation" looks like a safe way.
Unlike LIMITed select looks unpredictable to me.
Thanx for assistance :)
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2010-05-01 09:05 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-04-30 12:50 LIMIT problem silly sad <sad@bankir.ru>
2010-04-30 12:57 ` Nilesh Govindarajan <lists@itech7.com>
2010-05-01 08:55 ` silly sad <sad@bankir.ru>
2010-04-30 23:58 ` Jasen Betts <jasen@xnet.co.nz>
2010-05-01 09:05 ` silly sad <sad@bankir.ru>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox