Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id CDCCE6329F9 for ; Fri, 30 Apr 2010 20:58:36 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 90762-03 for ; Fri, 30 Apr 2010 23:58:29 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtpcorp.com (smtpcorp.com [67.192.120.76]) by mail.postgresql.org (Postfix) with ESMTP id 236B463266C for ; Fri, 30 Apr 2010 20:58:28 -0300 (ADT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpcorp.com; s=main; h=Content-Transfer-Encoding:Content-Type:Mime-Version:References:Message-ID:Date:Subject:From:To; bh=AQDCAugPCpFuSyvj7OG+2MSpNXArmknQmI9qbd7ADQQ=; b=rp0OmrfoS5N7geHjD5Ctumk1yk6mPD7+RWpdrNKZMkhevIJwaMfVnPytymq+afrfdqfz17HH6UvnViGEH5guS2t+nQkNkZubWjg1BSjEdPeGT6BTEYfWtfh7W8tVtwZj; Received: from ip-118-90-140-229.xdsl.xnet.co.nz ([118.90.140.229] helo=gonzo) by smtpcorp.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.70) id 1O806E-0007nD-ED; mid 144 for pgsql-sql@postgresql.org; Fri, 30 Apr 2010 23:58:02 +0000 Received: from news by gonzo with local (Exim 4.69) (envelope-from ) id 1O8063-000810-Kk for pgsql-sql@postgresql.org; Sat, 01 May 2010 11:58:15 +1200 To: pgsql-sql@postgresql.org Path: not-for-mail From: Jasen Betts Newsgroups: gmane.comp.db.postgresql.sql Subject: Re: LIMIT problem Date: 30 Apr 2010 23:58:15 GMT Organization: Dis (not Dat) Organisation Lines: 59 Message-ID: References: <4BDAD20A.1090503@bankir.ru> NNTP-Posting-Host: localhost Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: reversiblemaps.ath.cx 1272671895 30811 127.0.0.1 (30 Apr 2010 23:58:15 GMT) X-Face: ?)Aw4rXwN5u0~$nqKj`xPz>xHCwgi^q+^?Ri*+R(&uv2=E1Q0Zk(>h!~o2ID@6{uf8s; a +M[5[U[QT7xFN%^gR"=tuJw%TXXR'Fp~W; (T"1(739R%m0Yyyv*gkGoPA.$b,D.w:z+<'"=-lVT?6 {T?=R^:W5g|E2#EhjKCa+nt":4b}dU7GYB*HBxn&Td$@f%.kl^:7X8rQWd[NTc"P"u6nkisze/Q; 8 "9Z{peQF,w)7UjV$c|RO/mQW/NMgWfr5*$-Z%u46"/00mx-,\R'fLPe.)^ User-Agent: slrn/pre1.0.0-2 (Linux) X-Smtpcorp-Track: 1959541.1.31188160 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.559 tagged_above=-5 required=5 tests=AWL=1.759, BAYES_50=0.8 X-Spam-Level: ** X-Archive-Number: 201004/121 X-Sequence-Number: 34048 On 2010-04-30, silly sad 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.