Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1glH8x-0007Yu-P8 for pgsql-hackers@arkaria.postgresql.org; Sun, 20 Jan 2019 17:44:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1glH7x-0005Zc-JB for pgsql-hackers@arkaria.postgresql.org; Sun, 20 Jan 2019 17:43:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1glH7x-0005ZV-Bw for pgsql-hackers@lists.postgresql.org; Sun, 20 Jan 2019 17:43:21 +0000 Received: from bay.acenet.us ([173.230.252.50]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1glH7v-000220-6M for pgsql-hackers@lists.postgresql.org; Sun, 20 Jan 2019 17:43:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=anastigmatix.net; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:Cc:References:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=DkH0lrxOjEoJs1I0648bl5Qo8mVcN0JT+T4f4JXn9M8=; b=Xv5AdFDnY5qF6711OWtSd9BJxU aOf9wAd/bjxCvogMyg/7tEewMGfA8UhaUWnkpZ7ax5PMXrTCulwVaygU/eJDBI6U/orwFQE7Ki5SX 8bJNrkojo456WCavUn2hT9YiDxLTpDwO6uY3NVAd2pLlhz72R94QCoCcW9BE5zAp10pZqn5QtOUNv iF76iiKHB+R3t7+nl6qQMZ54Ae9zsEG6fXaeAjko2GFmdZCCbar+17r57Ht1LS30LAlemYhsDzsw9 fTVGbXrhpWzxx4XjXfiXhRlrjuNxA0mJFAZ8Uylx/Ztpl1/w/yVSQ+AZNGmUSitynAkbPQ5N96LtN 2v9dl2jg==; Received: from [192.182.57.242] (port=50306) by bay.acenet.us with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.91) (envelope-from ) id 1glH7r-008nAG-9Z; Sun, 20 Jan 2019 12:43:16 -0500 Subject: Re: PostgreSQL vs SQL/XML Standards To: Pavel Stehule References: <45C74339-3531-46BD-A595-37183C6730A1@winand.at> <5C283168.8060001@anastigmatix.net> <5C291741.9060506@anastigmatix.net> <5C297BB7.9070509@anastigmatix.net> <5C3A7A90.3070207@anastigmatix.net> <5C43FAEB.2070000@anastigmatix.net> <5C4401BE.4080606@anastigmatix.net> <5C449C71.7060903@anastigmatix.net> Cc: PostgreSQL Hackers From: Chapman Flack X-Enigmail-Draft-Status: N1110 Message-ID: <5C44B332.6070609@anastigmatix.net> Date: Sun, 20 Jan 2019 12:43:14 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-OutGoing-Spam-Status: No, score=-95.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bay.acenet.us X-AntiAbuse: Original Domain - lists.postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - anastigmatix.net X-Get-Message-Sender-Via: bay.acenet.us: authenticated_id: chap@anastigmatix.net X-Authenticated-Sender: bay.acenet.us: chap@anastigmatix.net X-Source: X-Source-Args: X-Source-Dir: X-From-Rewrite: unmodified, already matched List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 01/20/19 11:55, Pavel Stehule wrote: > input row mean a row of processed relation. The xml value from this row can > be transformed to 0..M output rows. > > The column filter expressions are evaluated once per input rows, default > expressions are evaluated when it is necessary - possibly once for any > output row > ... > it is expected - the input relation has four lines - the function was 4x > initialized. In this case 1 call of xmltable produces 1 row. Good ... I think we're converging on a shared understanding. I am just used to speaking of xmltable as a simple function that executes one row_expression one time against one supplied input, and generates 0..M output rows from it. If there are multiple rows in a relation that you want to apply xmltable to, that's a simple matter of calling xmltable multiple times (which is just what SQL is doing when the xmltable is on the RHS of an explicit or implied LATERAL). The upshot seems to be that there is nothing necessarily special about how xmltable treats its column_expressions: it compiles them once upon entry to the function, as one would naïvely expect. (Or, if there is anything more special about how the column_expression is being handled, it seems not to be necessary, as the naïve behavior would be adequate.) Accordingly, I think the paragraph beginning "Unlike regular PostgreSQL functions," is more likely to perplex readers than to enlighten them. What it says about column_expression does not seem to lead to any useful difference from the behavior if it were "just like regular PostgreSQL functions". The part about usefully using volatile functions in default_expression remains important to mention. The statement in an earlier paragraph that "It is possible for a default_expression to reference the value of output columns that appear prior to it in the column list" still may need some rework, because it does not seem possible to refer to prior columns /within xmltable's own column list/ (though that could be useful, and I think it is intended in the standard). Doesn't seem to work in Oracle either.... While it does seem possible to refer to columns supplied by /earlier FROM items in the containing SELECT/, that simply results in multiple calls of xmltable, just as in the column_expression case. >> I think the same example would produce the same output even with feature >> (2) >> absent. It's LATERAL doing the magic there. So I am doubtful that it >> demonstrates (2). > > LATERAL is necessary, because XMLTABLE can be used only in FROM clause, > and in this case XMLTABLE has mutable parameters. For what it's worth, if I repeat the query with the word LATERAL removed, it works just the same. I think that's simply because the LATERAL behavior is implied for a function-call FROM item, so the explicit word isn't needed. The main thing is, evaluation proceeds in the way described under LATERAL in the ref page for SELECT. Regards, -Chap