Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Upo0C-0007gG-6v for pgsql-general@arkaria.postgresql.org; Thu, 20 Jun 2013 23:10:52 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Upo0B-0001ke-Hr for pgsql-general@arkaria.postgresql.org; Thu, 20 Jun 2013 23:10:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Upo0A-0001kI-Ej for pgsql-general@postgresql.org; Thu, 20 Jun 2013 23:10:50 +0000 Received: from mail-ve0-x234.google.com ([2607:f8b0:400c:c01::234]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Upo07-0000VX-J1 for pgsql-general@postgresql.org; Thu, 20 Jun 2013 23:10:50 +0000 Received: by mail-ve0-f180.google.com with SMTP id pa12so5619549veb.39 for ; Thu, 20 Jun 2013 16:10:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:subject:from:reply-to:to:cc:date:in-reply-to:references :organization:content-type:x-mailer:mime-version:x-gm-message-state; bh=wpwmVMUwiLXoqe+7n1V8T1q7DjzBRMtVIUs5Z09sKJc=; b=i+8zHlfg2EL9PSfvRR1h8eCw+e9ccIsOMm/yce0DBCiq9rFIvchN2plI8uWoffDnjc NlpJdizNzVLApgyXoOt+ZQYnHjOFtVnNV1HhtngThafB+wTGmI4TvZU6n/tPvYuBKdXi K1HWKCwGQM35b2QbTjtwAjBiU/MqdZXVR3zfZOPvwbI41UF8DdBDPnKIO9ZlGMnq0w7p mzNePGeBsdtFFEbT5vKsXdaIgAcceLTo/Q8OdR8JvPLxuOFLcSO67twxxXD3OYYHuPuY XxtoO8nkYtYdh6h6q/94szlBv8q4zDsTu0EcQbk0jjrX6OAdNdIxeEXoIttLGjhRJ/Zs HtRA== X-Received: by 10.220.101.138 with SMTP id c10mr3956191vco.19.1371769845558; Thu, 20 Jun 2013 16:10:45 -0700 (PDT) Received: from [192.168.0.14] (cpe-108-182-79-95.nyc.res.rr.com. [108.182.79.95]) by mx.google.com with ESMTPSA id tu6sm2991601vec.2.2013.06.20.16.10.44 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 20 Jun 2013 16:10:44 -0700 (PDT) Message-ID: <1371769843.15253.51.camel@localhost.localdomain> Subject: Re: Re: Easiest way to compare the results of two queries row by row and column by column From: Jason Long Reply-To: mailing.lists@octgsoftware.com To: David Johnston Cc: pgsql-general@postgresql.org Date: Thu, 20 Jun 2013 18:10:43 -0500 In-Reply-To: <1371769520256-5760215.post@n5.nabble.com> References: <1371766705.15253.44.camel@localhost.localdomain> <1371769520256-5760215.post@n5.nabble.com> Organization: OCTG Software, LLC Content-Type: multipart/alternative; boundary="=-KsaV20ubSmEmo6fEFJZB" X-Mailer: Evolution 3.6.4 (3.6.4-3.fc18) Mime-Version: 1.0 X-Gm-Message-State: ALoCoQn5KnqYH8IyH2Xe58LeXDwRVIGFLfZtkUwCRgz3dvhKVCjyRFpYir4gzc3ngeL6iG4zfMCt X-Pg-Spam-Score: -0.8 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org --=-KsaV20ubSmEmo6fEFJZB Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Thank you. I will give it a try. I have never used WITH before. Thank you for the tips. On Thu, 2013-06-20 at 16:05 -0700, David Johnston wrote: > Jason Long-2 wrote > > Can someone suggest the easiest way to compare the results from two > > queries to make sure they are identical? > > First thing that comes to mind: > > WITH > before_qry (col1, col2, col3) AS ( VALUES (1,1,1),(2,2,2),(3,3,3) ) > , after_qry (col1, col2, col3) AS ( VALUES (1,1,1),(2,2,2),(3,3,3) ) > , before_array AS (SELECT array_agg(before_qry) AS before_agg_array > FROM before_qry) > , after_array AS (SELECT array_agg(before_qry) AS after_agg_array FROM > before_qry) > SELECT *, before_agg_array = after_agg_array > FROM before_array CROSS JOIN after_array > > Basically turn the resultsets into arrays (of composites) and then see if > the arrays are the same. This has issues with respect to column names and > comparable datatypes (i.e., if one column is bigint and the other is integer > they still compare equally). > > One thought would to only allow a view name (and possibly, separately, the > ORDER BY clause). Catalog lookups can be used to check for identical view > output types. > > No idea of something like this exists and is readily available. > > David J. > > > > > > > -- > View this message in context: http://postgresql.1045698.n5.nabble.com/Easiest-way-to-compare-the-results-of-two-queries-row-by-row-and-column-by-column-tp5760209p5760215.html > Sent from the PostgreSQL - general mailing list archive at Nabble.com. > > --=-KsaV20ubSmEmo6fEFJZB Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: 7bit Thank you.  I will give it a try.  I have never used WITH before.

Thank you for the tips.

On Thu, 2013-06-20 at 16:05 -0700, David Johnston wrote:
Jason Long-2 wrote
> Can someone suggest the easiest way to compare the results from two
> queries to make sure they are identical?

First thing that comes to mind:

     WITH 
       before_qry (col1, col2, col3) AS ( VALUES (1,1,1),(2,2,2),(3,3,3) )
     , after_qry  (col1, col2, col3) AS ( VALUES (1,1,1),(2,2,2),(3,3,3) )
     , before_array AS (SELECT array_agg(before_qry) AS before_agg_array
FROM before_qry)
     , after_array  AS (SELECT array_agg(before_qry) AS after_agg_array FROM
before_qry)
     SELECT *, before_agg_array = after_agg_array
     FROM before_array CROSS JOIN after_array

Basically turn the resultsets into arrays (of composites) and then see if
the arrays are the same.  This has issues with respect to column names and
comparable datatypes (i.e., if one column is bigint and the other is integer
they still compare equally).

One thought would to only allow a view name (and possibly, separately, the
ORDER BY clause).  Catalog lookups can be used to check for identical view
output types.

No idea of something like this exists and is readily available.

David J.






--
View this message in context: http://postgresql.1045698.n5.nabble.com/Easiest-way-to-compare-the-results-of-two-queries-row-by-row-and-column-by-column-tp5760209p5760215.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.



--=-KsaV20ubSmEmo6fEFJZB--