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.92) (envelope-from ) id 1j6hK0-0002gD-UA for pgsql-general@arkaria.postgresql.org; Tue, 25 Feb 2020 21:00:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j6hJy-0001TX-4U for pgsql-general@arkaria.postgresql.org; Tue, 25 Feb 2020 21:00:50 +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 1j6hJx-0001TQ-Mk for pgsql-general@lists.postgresql.org; Tue, 25 Feb 2020 21:00:49 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j6hJt-0000Au-27 for pgsql-general@postgresql.org; Tue, 25 Feb 2020 21:00:48 +0000 Received: by mail-pl1-x62b.google.com with SMTP id d9so299582plo.11 for ; Tue, 25 Feb 2020 13:00:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=illuminatedcomputing-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=yXPhultme3ZQ8zQXsTkH/BwnshsDxrzQgRkOrMPfkoo=; b=lQZ5OvPrUvtz7mdZadKkZ7vhPB7ZzxBTWFbVn49QF8mixEpGvrbmUTjzd2ytvA7lUC QZzGn5QYvSEwU7YFOPRiUCaCExPKniE/GWty6CCLCCD1jRl/HArkfGGS4kVC5ZgsBMNa TKXfiASHfd4bLyzITt2/Mbd7Cd+xODTbYL5gU93Aham60lH/yqqCw6b8zfwVjXGSAT59 B36P/09/bJEV0dxEifF8tYbngm3kcV5Lw6iPj//NfgMntoafOyZ9dmCiOm6nphnt8OZZ jZ88xeHi4wxCwPezeINjx1yF4zkFmbVX2BHPAKjTreqVfowo0qKfoy5hOY5m1l3+c/8N 6LvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=yXPhultme3ZQ8zQXsTkH/BwnshsDxrzQgRkOrMPfkoo=; b=EN6aKN8aAP/xcOcsq6AGTBDanmK3FK84cYnDBvO5PvMqnDZyz8HB8ZbwWHRFiG+811 bLismOntg017T9T2eLGnd72PC0sqE9oylQFhXu/1QqGq/avPchCK8bQ7tJy1rXNaq4cd TXzOl6u3+a7hNSUEENNRVs0xca6OKKH6SsR0exdrcbdBUyPeYnP/J0LZTb7mafSvBn/Q 3zrHqK7XLPeNnqA7EWHsgD3YNItFLqrRZomlTzwC8qh3u7z/dNJcdL05ByY0gAIROkiU lAmpd/qhptE/3pwPpkjZDc6Xx7kyJFelEFicxxLCpcc5p0fIFTGVe2s6U4J4WzbL3Mw6 4LJg== X-Gm-Message-State: APjAAAX3L4oNKdLt/JbNeEZpZOw8cZuB3CqM6T1aTfV3jGHUxz83uyIX E/OoBAnu24EDDX6ENF/dolKv/AGP0LE= X-Google-Smtp-Source: APXvYqwflzCmyIcAK7dq7SBMrL/fBctSruBbQ82ovhL1CI6OvEUIE0nOyJEoO5d8Eo8iL8/ZCKOKHw== X-Received: by 2002:a17:90a:f88:: with SMTP id 8mr1112394pjz.72.1582664442343; Tue, 25 Feb 2020 13:00:42 -0800 (PST) Received: from [192.168.2.101] (static-50-53-109-254.bvtn.or.frontiernet.net. [50.53.109.254]) by smtp.googlemail.com with ESMTPSA id g19sm18252742pfh.134.2020.02.25.13.00.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 Feb 2020 13:00:41 -0800 (PST) Subject: Re: a proposal for a new functionality: "SELECT * [EXCEPT col1 [,col2]] To: Stanislav Motycka Cc: PG-General Mailing List References: <88ec1892-2282-ab67-b2aa-1f69003e2392@gmail.com> From: Paul Jungwirth Message-ID: Date: Tue, 25 Feb 2020 13:00:40 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <88ec1892-2282-ab67-b2aa-1f69003e2392@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2/25/20 11:46 AM, Stanislav Motycka wrote: > > > Dňa 25. 2. 2020 o 20:28 Paul A Jungwirth napísal(a): >> I take the proposal to mean this: >> >> SELECT listOfColumns [EXCEPT listOfColumns] FROM ... > Exactly, simply exclude unneeded columns from the base clause "SELECT", > nothing more .. Not that this is necessarily fatal, but you'd need to avoid parsing trouble with the other EXCEPT, e.g. SELECT 1 EXCEPT SELECT 1; Believe it or not these are valid SQL: SELECT; SELECT EXCEPT SELECT; This fails today but only because of the different number of columns: SELECT 1 AS SELECT EXCEPT SELECT; So the parser understands it as selectQuery EXCEPT selectQuery, but you can see how it could also be parsable as this new structure. So the parser would have to decide which is meant (if that's even possible at that early stage). I guess as soon as you exclude two columns it is unambiguous though because of this comma: SELECT ... EXCEPT SELECT, .... And anyway I think for such a pathological case you could just tell people to add double quotes. Google Big Query was mentioned upthread. I see they require parens, e.g. SELECT ... EXCEPT (...). I don't think that actually fixes the ambiguity though. Also a few other notes (after very brief testing): SELECT * EXCEPT (foo) FROM t; -- works SELECT * EXCEPT (foo, bar) FROM t; -- works SELECT t.* EXCEPT (foo) FROM t; -- works SELECT * EXCEPT foo FROM t; -- fails SELECT foo, bar EXCEPT (foo) FROM t; -- fails SELECT t1.foo, t2.* EXCEPT (foo) FROM t1 JOIN t2 ON ...; -- works SELECT t2.*, t1.foo EXCEPT (foo) FROM t1 JOIN t2 ON ...; -- fails! So it seems they require at least one `*` in the SELECT target list. In fact the `*` must be the very last thing. Personally I think it should be as general as possible and work even without a `*` (let alone caring about its position). Regards, -- Paul ~{:-) pj@illuminatedcomputing.com