Re: adding support for zero-attribute unique/etc keys - Mailing list pgsql-hackers

From Gavin Flower
Subject Re: adding support for zero-attribute unique/etc keys
Date
Msg-id 5151EDAA.1020505@archidevsys.co.nz
Whole thread Raw
In response to Re: adding support for zero-attribute unique/etc keys  (Darren Duncan <darren@darrenduncan.net>)
List pgsql-hackers
<div class="moz-cite-prefix">On 27/03/13 06:14, Darren Duncan wrote:<br /></div><blockquote
cite="mid:5151D77B.5050801@darrenduncan.net"type="cite">On 2013.03.26 1:40 AM, Albe Laurenz wrote: <br /><blockquote
type="cite">DarrenDuncan wrote: <br /><blockquote type="cite">So, determining if 2 rows are the same involves an
iterationof dyadic logical <br /> AND over the predicates for each column comparison.  Now logical AND has an <br />
identityvalue, which is TRUE, because "TRUE AND p" (and "p AND TRUE") results <br /> in "p" for all "p".  Therefore,
any2 rows with zero columns each are the same. <br /><br /> Since any 2 rows with zero columns are the same, the
"UNIQUEpredicate" is FALSE <br /> any time there is more than 1 row in a table. <br /><br /> Does anyone agree or
disagreewith this logic? <br /></blockquote><br /> Yes :^) <br /><br /> You could use the same kind of argument like
this:<br /><br /> UNIQUE is true iff any two rows in T satisfy for each column: <br /> the column in row 1 is null OR
thecolumn in row 2 is null OR <br /> the column in row 1 is distinct from the column in row 2 <br /><br /> Now you you
iterateyour logical AND over this predicate <br /> for all columns and come up with TRUE since there are none. <br />
ConsequentlyUNIQUE is satisfied, no matter how many rows there are. <br /><br /> In a nutshell: <br /> All members of
theempty set satisfy p, but also: <br /> all members of the empty set satisfy the negation of p. <br /><br /> You can
usethis technique to make anything plausible. <br /></blockquote><br /> Consider the context however.  We're talking
abouta UNIQUE constraint and so what we want to do is prevent the existence of multiple tuples in a relation that are
thesame for some defined subset of their attributes.  I would argue that logically, and commonsensically, two tuples
withno attributes are the same, and hence a set of distinct tuples having zero attributes could have no more than one
member,and so a UNIQUE constraint over zero attributes would say the relation can't have more than one tuple.  So
unlesssomeone wants to argue that two tuples with no attributes are not the same, my interpretation makes more sense
andis clearly the one to follow. -- Darren Duncan <br /><br /><br /><br /></blockquote><font size="-1">Hmm as a user, I
wouldlike at most one row with empty fields covered by <font size="-1">a unique index</font></font>.<br /><br />
Logicalarguments to the contrary, remind me of the joke of the school boy who told his unlearned father that he had
learntlogic and could prove that his father actually had 3 fish in his basket despite both seeing only 2 fish.  His
unlearnedfather did not try to argue, and simply said: well your mother can have the first fish, I'll have the second,
andthat his learned son could have the third...<br /><br /><br /> 

pgsql-hackers by date:

Previous
From: Fujii Masao
Date:
Subject: Re: Support for REINDEX CONCURRENTLY
Next
From: Stefan Kaltenbrunner
Date:
Subject: spoonbill vs. -HEAD