0

I have two tables that have the same fields. I want to compare each field of one table with the fields of the other table and report back any difference in the data.

I would like to do this in a dynamic way with out having to hard code the name of the fields in my query. Is this even possible or should I find a solution to this by using Python?

Example of tables:

     TABLE 1                    TABLE 2
FIELD1 : VALUE1            FIELD1 : VALUE1
FIELD2 : VALUE2            FIELD2 : VALUE2
FIELD3 : VALUE3            FIELD3 : VALUE3xxx

Query goes through all the fields and then says "A ha" Field3 do not match, I must show this to the end user"

  • Generally we ask that you *search for similar or identical answers before posting*. Google is also a good idea. In this case, a quick search locates http://pgfoundry.org/projects/pg-comparator/ ... – Craig Ringer Aug 23 '15 at 11:05

1 Answers1

1

You have to create a Dinamic Sql and put it inside a function

Dynamic sql in postgres

For start you need contruct a sql to compare field name

And to get a table field names

select column_name from information_schema.columns where
table_name='table 1';
Community
  • 1
  • 1
Juan Carlos Oropeza
  • 47,252
  • 12
  • 78
  • 118
  • Yeah, I need to read upon Dynamic SQL. I started approaching the solution to my little problem by using Python. If it gets too messy/dirty I will drop it though. Thank you for your pointer by the way. Dynamic SQL is a good topic to know and I had forgotten it even existed. – George Mastrokostas Aug 22 '15 at 23:01