Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-23 Thread Jim Nasby
On 2/23/17 3:33 PM, Corey Huinker wrote: I've had to do it with temp tables any time the environment is different between control/experiment, which is the case when you're developing a drop-in replacement for an SRF or view or whatever. FWIW I'd recommend temp views, to give the planner the mos

Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-23 Thread Nico Williams
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 .*

Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-23 Thread Corey Huinker
> > FWIW I've found myself needing the precursor to this this (give me the > full diff) at least a couple times, and it's quite a PITA on anything but a > trivial relation. > > It's also not possible to make this easier via an SRF because you don't > know in advance what the result set looks like.

Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-23 Thread Nico Williams
On Tue, Feb 07, 2017 at 10:58:41AM -0500, Tom Lane wrote: > Joel Jacobson writes: > > Currently there is no simple way to check if two sets are equal. > > Uh ... maybe check whether SELECT set1 EXCEPT SELECT set2 > and SELECT set2 EXCEPT SELECT set1 are both empty? Even better, NATURAL(*) FULL O

Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-23 Thread Jim Nasby
On 2/7/17 12:03 PM, Tom Lane wrote: 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

Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-08 Thread David G. Johnston
On Wed, Feb 8, 2017 at 10:30 AM, Tom Lane wrote: > David Fetter writes: > > On Wed, Feb 08, 2017 at 11:22:56AM -0500, Tom Lane wrote: > >> Yes. I think a new set-operation keyword would inevitably have to > >> be fully reserved --- UNION, INTERSECT, and EXCEPT all are --- which > >> means that

Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-08 Thread Tom Lane
David Fetter writes: > On Wed, Feb 08, 2017 at 11:22:56AM -0500, Tom Lane wrote: >> Yes. I think a new set-operation keyword would inevitably have to >> be fully reserved --- UNION, INTERSECT, and EXCEPT all are --- which >> means that you'd break every application that has used that word as >> a

Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-08 Thread David Fetter
On Wed, Feb 08, 2017 at 11:22:56AM -0500, Tom Lane wrote: > Robert Haas writes: > > On Wed, Feb 8, 2017 at 4:24 AM, Pantelis Theodosiou > > wrote: > >> I'm not advocating it but I don't see how introducing new SQL keywords > >> breaks backwards compatibility. > > > It does at least a little bit

Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-08 Thread Tom Lane
Robert Haas writes: > On Wed, Feb 8, 2017 at 4:24 AM, Pantelis Theodosiou > wrote: >> I'm not advocating it but I don't see how introducing new SQL keywords >> breaks backwards compatibility. > It does at least a little bit. Yes. I think a new set-operation keyword would inevitably have to be

Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-08 Thread Robert Haas
On Wed, Feb 8, 2017 at 4:24 AM, Pantelis Theodosiou wrote: > I'm not advocating it but I don't see how introducing new SQL keywords > breaks backwards compatibility. It does at least a little bit. This starts failing: select 1 new_keyword form blah; (now you have to insert AS or quote the keyw

Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-08 Thread Pantelis Theodosiou
On Tue, Feb 7, 2017 at 3:13 PM, Joel Jacobson wrote: > Hi hackers, > > Currently there is no simple way to check if two sets are equal. > > Looks like no RDBMS in the world has a simple command for it. > > You have to do something like: > > ... > > Introducing new SQL keywords is of course not a

Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-08 Thread Pantelis Theodosiou
On Tue, Feb 7, 2017 at 3:58 PM, Tom Lane wrote: > Joel Jacobson writes: > > Currently there is no simple way to check if two sets are equal. > > Uh ... maybe check whether SELECT set1 EXCEPT SELECT set2 > and SELECT set2 EXCEPT SELECT set1 are both empty? > > regards, tom

Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-07 Thread Merlin Moncure
1On Tue, Feb 7, 2017 at 9:46 PM, Joel Jacobson wrote: > On Tue, Feb 7, 2017 at 4:58 PM, Tom Lane wrote: >> Joel Jacobson writes: >>> Currently there is no simple way to check if two sets are equal. >> >> Uh ... maybe check whether SELECT set1 EXCEPT SELECT set2 >> and SELECT set2 EXCEPT SELECT s

Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-07 Thread Fabien COELHO
Currently there is no simple way to check if two sets are equal. My 0.02€: Assuming that you mean set = relation, and that there is a key (which should be the case for a set otherwise tuples cannot be distinguished, so this is not really a set), and assuming not null other data, then: CRE

Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-07 Thread Tom Lane
"David G. Johnston" writes: > On Tue, Feb 7, 2017 at 8:58 AM, Tom Lane wrote: >> Joel Jacobson writes: >>> Currently there is no simple way to check if two sets are equal. >> Uh ... maybe check whether SELECT set1 EXCEPT SELECT set2 >> and SELECT set2 EXCEPT SELECT set1 are both empty? > ​SELE

Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-07 Thread David G. Johnston
On Tue, Feb 7, 2017 at 8:58 AM, Tom Lane wrote: > Joel Jacobson writes: > > Currently there is no simple way to check if two sets are equal. > > Uh ... maybe check whether SELECT set1 EXCEPT SELECT set2 > and SELECT set2 EXCEPT SELECT set1 are both empty? > ​SELECT set1 FULL EXCEPT SELECT set2

Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-07 Thread Joel Jacobson
On Tue, Feb 7, 2017 at 6:28 PM, David Fetter wrote: > This could be shortened further to the following if we ever implement > DISTINCT for window functions, which might involve implementing > DISTINCT via hashing more generally, which means hashable > types...whee! > > SELECT array_agg(DISTINCT (a

Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-07 Thread David Fetter
On Tue, Feb 07, 2017 at 09:10:17AM -0800, David Fetter wrote: > On Tue, Feb 07, 2017 at 04:13:40PM +0100, Joel Jacobson wrote: > > Hi hackers, > > > > Currently there is no simple way to check if two sets are equal. > > Assuming that a and b each has at least one NOT NULL column, is this > simpl

Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-07 Thread David Fetter
On Tue, Feb 07, 2017 at 04:13:40PM +0100, Joel Jacobson wrote: > Hi hackers, > > Currently there is no simple way to check if two sets are equal. Assuming that a and b each has at least one NOT NULL column, is this simple enough? Based on nothing much, I'm assuming here that the IS NOT NULL tes

Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-07 Thread Joel Jacobson
On Tue, Feb 7, 2017 at 4:58 PM, Tom Lane wrote: > Joel Jacobson writes: >> Currently there is no simple way to check if two sets are equal. > > Uh ... maybe check whether SELECT set1 EXCEPT SELECT set2 > and SELECT set2 EXCEPT SELECT set1 are both empty? Yes, that's one way, but it's ugly as you

Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-07 Thread Tom Lane
Joel Jacobson writes: > Currently there is no simple way to check if two sets are equal. Uh ... maybe check whether SELECT set1 EXCEPT SELECT set2 and SELECT set2 EXCEPT SELECT set1 are both empty? regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers

Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-07 Thread Joel Jacobson
But that's already a valid statement, so there is no ambiguity: SELECT TRUE WHERE FALSE IS NOT DISTINCT FROM (SELECT TRUE); bool -- (0 rows) If you want to compare the set (SELECT TRUE WHERE FALSE) with the set (SELECT TRUE) then just add parenthesis: (SELECT TRUE WHERE FALSE) IS NOT DISTIN

Re: [HACKERS] Idea on how to simplify comparing two sets

2017-02-07 Thread Anders Granlund
What about this ambiguity? SELECT TRUE WHERE FALSE IS NOT DISTINCT FROM (SELECT TRUE) On Tue, Feb 7, 2017 at 4:13 PM, Joel Jacobson wrote: > Hi hackers, > > Currently there is no simple way to check if two sets are equal. > > Looks like no RDBMS in the world has a simple command for it. > > Yo