Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kKtfg-0001c1-TO for pgsql-general@arkaria.postgresql.org; Wed, 23 Sep 2020 01:34:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kKtff-0002TP-GJ for pgsql-general@arkaria.postgresql.org; Wed, 23 Sep 2020 01:34:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kKtff-0002TH-8k for pgsql-general@lists.postgresql.org; Wed, 23 Sep 2020 01:34:11 +0000 Received: from ook.raf.org ([2402:1f00:8100:400::31]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kKtfb-0008F6-Ty for pgsql-general@postgresql.org; Wed, 23 Sep 2020 01:34:10 +0000 Received: from localhost (localhost [127.0.0.1]) by ook.raf.org (Postfix) with ESMTP id D4D365DE30 for ; Wed, 23 Sep 2020 11:34:02 +1000 (AEST) X-Virus-Scanned: Debian amavisd-new at ook.raf.org Received: from ook.raf.org ([127.0.0.1]) by localhost (ook.raf.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VctN3B5s_BZ3 for ; Wed, 23 Sep 2020 11:34:02 +1000 (AEST) Received: by ook.raf.org (Postfix, from userid 1001) id 6CD565E31B; Wed, 23 Sep 2020 11:34:02 +1000 (AEST) Date: Wed, 23 Sep 2020 11:34:02 +1000 From: raf To: pgsql-general@postgresql.org Subject: I'm surprised that this worked Message-ID: <20200923013402.56zpnae4ocdu43cr@raf.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, I just wrote a query that I didn't expect to work but I was pleasantly surprised that it did. It looked something like this: select a.aaa, c.ccc, d.ddd1, d.ddd2 from tbla a, tblb b, tblc c, funcd(c.id) d where a.something = something and b.something = a.something and c.something = b.something How does it know which c.id to use for the function without going all cartesian product on me? Maybe it makes no sense for such a parameterised function to be part of a cartesian product. Actually, that function returns a setof record but only ever a single record. That might be relevant. I was sure I'd done something similar once that (sensibly) didn't work, and I needed a loop to call the function in, but I might be thinking of something in an outer join's "on" clause. Does that make sense? Even more impressed with Postgresql than usual. :-) cheers, raf