Pergunta

Hi I'm extremely new to PostgresSQL.

I have created a few tables and managed to alter table's and columns but I can't seem to grasp the inherit's part of it.

I have been struggleing with this part for a while now.

I created a table but have found out I need to create a table that inherits from 9 other tables and when those 9 other tables get changed the newely created table has to get the changed too.

I have tried a few steps but seem to be either missing an important part of the procedure or doing it wrong.

My steps are as follows:

CREATE TABLE data."Test" (
  "OID" integer,
  "CMAID" integer,
  "UpdateDate" timestamp without time zone,
  "SG21CODE" character varying(21),
  "ErfExtent" integer,
  "ZoneBlocked" smallint,
  "MunValue" integer,
  "MunValueYear" integer,
  "PurchasePrice" integer,
  "PurchaseDate" timestamp without time zone,
  "RegisteredDate" timestamp without time zone,
  "ReportedSalePrice" integer,
  "ReportedSaleDate" timestamp without time zone,
  "BondHolder" character varying(32),
  "BondAmount" bigint,
  "DateIncluded" timestamp without time zone,
  "SchemeNo" money,
  geometry geometry(Geometry,3857),
  "EUCat" text,
  "UseCode" text,
  "MUNCODE" text,
  "SGUSAGE" text,
  "ZoneDesc" text,
  "Remainder" text,
  "SiteOnly" text,
  "RegStatus" text,
  "Buyer" text,
  "SaleStatus" text,
  "SaleType" text,
  "TitleDeed" text,
  "PostCode" text,
  "Address4" text,
  "Address3" text,
  "Address2" text,
  "Address1" text,
  "Ratepayer" text,
  "OwnerIDNo" text,
  "Owner" text,
  "Zone" text,
  "ErfUsage" text,
  "Type" text,
  "Suburb" text,
  "SubSuburb" text,
  "Complex" text,
  "StreetName" text,
  "Allotment" text,
  "StreetNo" text,
  "SchemeName" text,
  "ErfNo" text,
   version integer
  );

SELECT *
FROM data."WC",data."NW",data."NC",data."MP",data."LP",data."KZN",data."GP",data."FS",data."EC"
INHERITS ("WC","NW","NC","MP","LP","KZN","GP","FS","EC");

For some reason when I run it, it just seems to run for ever but when I treid it with one table it ran (took a little while) but showed up the tables although when I went into the table of test there was nothing in the table except for the columns that had been created.

Like I said I'm relatively new to postgreSQL. See when It goes into geoserver then geoserver reads only the test table and not all 9 tables in a way. But If i need to make a change in any of the 9 tables that the main geoserver table picks up on the changes and overwrite the new changes over the old ones.

Foi útil?

Solução

That query doesn't even come close to what you think it does. INHERITS overrides column names in one of your tables, and you are cross-joining 9 tables against eachother. At any rate INHERITS in select statements seems to be totally undocumented so it may be a bug or a feature, or just undefined behavior.

Get rid of the INHERITS clause and add UNION instead of implicit cross joins in your FROM clause.

SELECT * FROM data."WC"
UNION ALL
SELECT * FROM data."NW"
....
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top