Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ch1NW-0003J2-1S for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Feb 2017 21:56:46 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ch1NV-00020n-BV for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Feb 2017 21:56:45 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ch1M5-0000QE-Ce for pgsql-hackers@postgresql.org; Thu, 23 Feb 2017 21:55:17 +0000 Received: from sub4.mail.dreamhost.com ([69.163.253.135] helo=homiemail-a55.g.dreamhost.com) by makus.postgresql.org with esmtps (TLS1.1:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1ch1Ly-0000T8-As for pgsql-hackers@postgresql.org; Thu, 23 Feb 2017 21:55:15 +0000 Received: from homiemail-a55.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a55.g.dreamhost.com (Postfix) with ESMTP id 52DA068003C2B; Thu, 23 Feb 2017 13:55:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=cryptonector.com; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=cryptonector.com; bh=Cm4KGw9qc5QQdd /RqnfL8YXXodA=; b=UH6prxcFN9LvOXOXFH6Cuh3wDp2/nSQyK1/UeJr71Op5j9 dywBykCKIRGFcJUcgF0qPfrZFCRRezJlGX3udSJNxsipsSzQATJX8+VmUQiUy1st T1ogcS3G6Wo4nZtl7So96Ivz+bPeBrBcMzX3/2hfEo0c61NioLkG0FqE3da/U= Received: from localhost (cpe-70-123-158-140.austin.res.rr.com [70.123.158.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: nico@cryptonector.com) by homiemail-a55.g.dreamhost.com (Postfix) with ESMTPSA id 4CD3E68003C29; Thu, 23 Feb 2017 13:55:07 -0800 (PST) Date: Thu, 23 Feb 2017 15:55:03 -0600 From: Nico Williams To: Tom Lane Cc: "David G. Johnston" , Joel Jacobson , Pg Hackers Subject: Re: Idea on how to simplify comparing two sets Message-ID: <20170223215457.GE30233@localhost> References: <15376.1486483121@sss.pgh.pa.us> <6491.1486490594@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6491.1486490594@sss.pgh.pa.us> User-Agent: Mutt/1.5.24 (2015-08-30) X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On Tue, Feb 07, 2017 at 01:03:14PM -0500, Tom Lane wrote: > "David G. Johnston" writes: > > Actually ... now that you mention full join, I believe this works: > > select * from (select ...) s1 full join (select ...) s2 > on ((s1.*)=(s2.*)) where s1.* is distinct from s2.*; You can drop the .*s: select * from (select ...) s1 full join (select ...) s2 on s1 = s2 where s1 is distinct from s2; And even: select s1, s2 from (select ...) s1 natural full outer join (select ...) s2; This makes it possible to write very generic (schema-wise) code for comparing table sources. As I've mentioned elsewhere, there is an issue with NULLs in columns... I really, really would like either a full equijoin where equality treats NULL = NULL -> true for this purpose, or a natural join where only primary key or not-nullable columns are used, or a USING clause form where I can specify such behavior without having to list all the columns that should be used. I use NATURAL FULL OUTER JOIN for computing materialized view diffs in my alternate view materialization system. NULLs are poison for this purpose, yielding false positive differences. But my code also uses the table row value form above in order to avoid having to generate column lists for a USING clause or expressions for ON. These requests are not for syntactic sugar, not really. But I realize they may be non-trivial -- I may be looking for unobtanium. > > That said I'm not sure how much we want to go down this road on our own. > > It'd be nice to have when its needed but its not something that gets much > > visibility on these lists to suggest a large pent-up demand. > > Yeah, if this isn't in the standard and not in other databases either, > that would seem to suggest that it's not a big requirement. SQLite3 famously lacks FULL joins. It kills me because the alternative constructions become O(N log M) instead of O(N) for a properly implemented FULL join (assuming suitable indices anyways). I wouldn't suggest that that's a reason not to support FULL joins in any other RDBMS, rather, I'd suggest that SQLite3 is missing an important feature. Pardon the tangent. It may not really be applicable here, as here I think OP is looking for syntactic sugar rather than an important optimization. But the point is that sometimes you have to lead the standards-setting and/or the competition. Nico -- -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers