PostgreSQL: relation would be inherited from more than once
The error indicates, "the table is already inherited with same or other parent table.

Here is an example:


Create three tables Table_A, Table_B &amp; Table_C and insert similar values to all of th three tables.


    CREATE TABLE Table_A
    (
                                            EmpId int,
                                            EName varchar(128)
    );

    INSERT INTO Table_A(EmpId,EName)
    VALUES(1,'Rajesh');
    INSERT INTO Table_A(EmpId,EName)
    VALUES(2,'Ranjan');
    INSERT INTO Table_A(EmpId,EName)
    VALUES(3, 'Alok');

    CREATE TABLE Table_B
    (
                                            EmpId int,
                                            EName varchar(128)
    );

    INSERT INTO Table_B(EmpId,EName)
    VALUES(1,'Rajesh');
    INSERT INTO Table_B(EmpId,EName)
    VALUES(2,'Ranjan');
    INSERT INTO Table_B(EmpId,EName)
    VALUES(3, 'Alok');

    CREATE TABLE Table_C
    (
                                            EmpId int,
                                            EName varchar(128)
    );

    INSERT INTO Table_C(EmpId,EName)
    VALUES(1,'Rajesh');
    INSERT INTO Table_C(EmpId,EName)
    VALUES(2,'Ranjan');
    INSERT INTO Table_C(EmpId,EName)
    VALUES(3, 'Alok');



Then execute ALTER statement to add inheritance. For both alter statements executed successfully.


    ALTER TABLE PUBLIC.Table_A INHERIT PUBLIC.Table_B;

    Result:
    ALTER TABLE
    Query returned successfully in 132 msec.

    ALTER TABLE PUBLIC.Table_A INHERIT PUBLIC.Table_C;

    Result:
    ALTER TABLE
    Query returned successfully in 137 msec.



Now execute the same ALTER statement again and it'll result similar error.


    ERROR:  relation "table_c" would be inherited from more than once
    SQL state: 42P07


You can use following query to find inherited tables.

SELECT
    A.*, c.relname AS child, C.relname AS parent
FROM
    pg_inherits A
INNER JOIN  pg_class AS B ON (A.inhrelid=B.oid)
INNER JOIN pg_class AS C ON (A.inhparent=C.oid);