Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 4ADC01337B58 for ; Wed, 13 Oct 2010 00:16:53 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 44879-07 for ; Wed, 13 Oct 2010 03:16:46 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from benix.tamu.edu (ben.tamu.edu [165.91.232.129]) by mail.postgresql.org (Postfix) with ESMTP id EAF8B1337B50 for ; Wed, 13 Oct 2010 00:16:45 -0300 (ADT) Received: from benix.tamu.edu (localhost.localdomain [127.0.0.1]) by benix.tamu.edu (8.14.4/8.14.3) with ESMTP id o9D3GiZ0002146; Tue, 12 Oct 2010 22:16:44 -0500 Received: (from bkim@localhost) by benix.tamu.edu (8.14.4/8.14.4/Submit) id o9D3GhnD002144; Tue, 12 Oct 2010 22:16:43 -0500 Date: Tue, 12 Oct 2010 22:16:43 -0500 From: Ben Kim To: Kevin Grittner Cc: Richard Broersma , pgsql-admin@postgresql.org Subject: Re: compare two rows Message-ID: <20101013031643.GC1813@tamu.edu> References: <4CB479DB02000025000368A9@gw.wicourts.gov> <20101012201747.GA720@tamu.edu> <20101012221055.GC985@tamu.edu> <4CB49B3402000025000368C0@gw.wicourts.gov> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4CB49B3402000025000368C0@gw.wicourts.gov> User-Agent: Mutt/1.5.20 (2009-12-10) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201010/105 X-Sequence-Number: 35846 > > create table test_dup (id serial primary key, val text); > > > How can I check whether the two rows are the same or different? > > Well, with a primary key in there, they had *better* be different. > > It would seem you want to see if some *subset* of the columns in two > rows match? All columns except those in the primary key? > > The next question is whether you want to just compare two specific > rows or list all duplicates. I was wanting something like select row(select ... from test_dup where id=1) = row(select ... from test_dup where id=2) where ... is all fields except the primary key field. (Which can be more than 100 fields in some tables.) I guess I've roughly found what I need between the answers posted. select row(t1.*) = row(t2.*) from (select val1, val2, val3, ..., val100 from test_dup where id=1) t1, (select val1, val2, val3, ..., val100 from test_dup where id=2) t2 ; This gave me a blank row when all of val1 ... val100 matched, and a value of "f" when something did not match. (Wish there was a shorthand way to express "all fields (*) except id field". Is it possible?) Thanks. Ben Kim