agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Willem Leenen <willem_leenen@hotmail.com>
To: kamauallan@gmail.com
To: pgsql-sql@postgresql.org
Subject: Re: How to compare two tables in PostgreSQL
Date: Mon, 12 Nov 2012 09:13:04 +0000
Message-ID: <DUB104-W340F2CF90F7096079209818F6D0@phx.gbl> (raw)
In-Reply-To: <CAF3N6oTJ4TiM2krTk6vyrELH8k7E_-B_RAmaDOOwQ-RCvBZzTg@mail.gmail.com>
References: <CA+MnYCqoDRAQRzJQ2pi4jbZkyDdHtpszc4JH+hFT2TkaE86bxQ@mail.gmail.com>
	<50A0A3DE.7070701@gmail.com>
	<CAF3N6oTJ4TiM2krTk6vyrELH8k7E_-B_RAmaDOOwQ-RCvBZzTg@mail.gmail.com>


 
My advice: for comparing databases, tables , data etc, don't go scripting yourself. There are already tools in the market for that and they give nice reports on differences in constraints, indexes, columnnames, data etc. 
I used dbdiff from dkgas.com, but it seems the website is down.  

I would try to stick to SQL solutions as much as possible, instead of creating files and compare them. (got that from Joe Celko ;) )
 
 
 



Date: Mon, 12 Nov 2012 11:00:32 +0300
Subject: Re: [SQL] How to compare two tables in PostgreSQL
From: kamauallan@gmail.com
To: pgsql-sql@postgresql.org



If you would like to compare their contents perhaps this may help.
Write a select statement containing the fields for which you would like to compare data for, you may want to leave out fields whose values are provided by default for example fields populated from sequence object and/or timestamp fields.
You may need to include triming of leading and trailing empty spaces for the text based fields if such white spaces are not relevant for your defination of similarity.
The same may apply on rounding and formatting numeric data for example 9.900 could be equivalent to 9.9 in the other table based on your application of the data.
Include an ORDER BY clause to ensure you get the records in a predictable order.
Output these data to a CSV file without the CSV header.
Now rewrite the same query for the other table, this is required if the table definations are not common between the two tables.
Remember to substitute the table name accordingly.
Output these data to another CSV file without the CSV header.


Now run sha1sum on the first file and compare the returned sha1sum value with the value returned on running sha1sum with the second file.
Perhaps use "diff" tool.


Allan.



On Mon, Nov 12, 2012 at 10:23 AM, Rob Sargentg <robjsargent@gmail.com> wrote:



On 11/10/2012 08:13 PM, saikiran mothe wrote:

Hi,

How can i compare two tables in PostgreSQL.

Thanks,
Sai
Compare their content or their definition?


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

 		 	   		  =

view thread (9+ messages)  latest in thread

Message-ID: <DUB104-W340F2CF90F7096079209818F6D0@phx.gbl>
Permalink:  ../DUB104-W340F2CF90F7096079209818F6D0@phx.gbl/
Also on:    postgresql.org/message-id/DUB104-W340F2CF90F7096079209818F6D0@phx.gbl

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: willem_leenen@hotmail.com, kamauallan@gmail.com
  Subject: Re: How to compare two tables in PostgreSQL
  In-Reply-To: <DUB104-W340F2CF90F7096079209818F6D0@phx.gbl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox