Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id A4F27633AF4 for ; Sun, 3 May 2009 00:47:53 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 35605-09 for ; Sun, 3 May 2009 00:47:51 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from yw-out-2324.google.com (yw-out-2324.google.com [74.125.46.31]) by mail.postgresql.org (Postfix) with ESMTP id A2498633AD9 for ; Sun, 3 May 2009 00:47:51 -0300 (ADT) Received: by yw-out-2324.google.com with SMTP id 3so1946778ywj.73 for ; Sat, 02 May 2009 20:47:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=J4dc+iwyK/2IQWcTe0bU9OO28J2m9fRz1mFEHJymSt4=; b=olqfseFg03Rx3o+lT2nyfELLGOYCugWjeblWNvqpQDf+j7L7aXCQW713Qc9DCSH/0s EodtvnTY+bEjUo0Ox6zMX+wH/bvieT2mD+40hOtmIcgxf9HTwVSSyRFKQanYYInExqLF 5g9V+RExSnbb783g/39kL9r7ObdShEDqH9g8Y= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=gu70BVmpFnySha5RuPdKcxoxLM9PfW2HSrw+OLnFnEhM1fqi4mfX6QD2XP3uaf/UXD kar82WnYq2AdTMQ192FRpO9oE5Rl3VxbmqdwLNp9dXgRmFNh3D5GChC4FaXydxmxAN/Z zYBqF090raEc3rZG+yL/EERqt/Z2xxCXah9V0= MIME-Version: 1.0 Received: by 10.151.121.10 with SMTP id y10mr9213720ybm.26.1241322470921; Sat, 02 May 2009 20:47:50 -0700 (PDT) In-Reply-To: References: <328DDBBB-31C4-41D7-BF0E-5ADD732F2B9F@mac.com> <20090430033747.GB1126@eddie> Date: Sat, 2 May 2009 23:47:50 -0400 Message-ID: Subject: Re: Comparing two tables of different database From: Isaac Dover To: pgsql-sql@postgresql.org Content-Type: multipart/alternative; boundary=001e680f08c4ee56360468f9e843 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200905/9 X-Sequence-Number: 32501 --001e680f08c4ee56360468f9e843 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Thank you, Lucas. I'm from the MS world, still learning these PG things. Though, it appears that the difference is somewhat minor. In my actual implementation, [other database] would be a linked server, which sounds like it would be similar to the PG dblink. Regardless, I've found information schema to be incredibly valuable. Thanks, - Isaac On Sat, May 2, 2009 at 5:25 PM, Lucas Brito wrote: > 2009/5/2 Isaac Dover > >> i've not tried this in postgres, but using information_schema makes >> comparing structures of databases trivial. i've been using this query for a >> while with MSSQL. Maybe this helps to answer the question. >> >> - isaac >> >> select ST.Table_Name, ST.Column_Name, DV.Table_Name, DV.Column_Name, * >> from [database].information_schema.Columns ST >> full outer join [other database].information_schema.Columns DV >> on ST.Table_Name = DV.Table_name >> and ST.Column_Name = DV.Column_Name >> where ST.Column_Name is null or DV.Column_Name is NULL >> >> > > Isaac, this query will return "ERROR: cross-database references are not > implemented". > > Postgres does not support queries in databases other than current one. Even > a simple select * from otherdatabase.information_schema.columns will not > work and throw the same error. > > However this can be done with dblink function like: > > select ST.Table_Name, ST.Column_Name, DV.Table_Name, DV.Column_Name, * > from information_schema.Columns ST > full outer join dblink('dbname=otherdatabase','select Table_Name, > Column_Name from information_schema.Columns') DV(Table_Name text, > Column_Name text) > on ST.Table_Name = DV.Table_name > and ST.Column_Name = DV.Column_Name > where ST.Column_Name is null or DV.Column_Name is NULL > > -- > Lucas Brito > > --001e680f08c4ee56360468f9e843 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Thank you, Lucas. I'm from the MS world, still learning these PG= =A0things. Though, it appears that the difference is somewhat minor. In my = actual implementation, [other database] would be a linked server, which sou= nds like it would be similar to the PG dblink. Regardless, I've found i= nformation schema to be incredibly valuable.
=A0
Thanks,
- Isaac

On Sat, May 2, 2009 at 5:25 PM, Lucas Brito <lucas75@gmail.com> wrote:

--001e680f08c4ee56360468f9e843--