1

when I execute the following UNION ALL code to combine several tables into one materialized view I get the error: column >>?column?<< specified several times. As you can see above the code, i strictly hold on to the sequence from the original tables.

    1. name
    1. info1 AS hoehe
    1. info1 AS art
    1. info1 AS name_alternative
    1. info2 AS region
    1. info3 AS text_hoehe
    1. kn AS name_lang
    1. geoloc
    1. symbolnummer

DROP MATERIALIZED VIEW vt_views.poi_test;

CREATE MATERIALIZED VIEW vt_views.poi_test
TABLESPACE pg_default
AS
 SELECT tim_bergname.name,
 tim_bergname.info1 AS hoehe,
 NULL,
 NULL,
 tim_bergname.info2 AS region,
 NULL,
 NULL,
 tim_bergname.geoloc,
 tim_bergname.symbolnummer
 FROM tim_bergname

UNION ALL

SELECT tim_flurname.name,
 NULL,
 NULL,
 NULL,
 NULL,
 NULL,
 NULL,
 tim_flurname.geoloc,
 tim_flurname.symbolnummer
 FROM tim_flurname

UNION ALL

SELECT tim_haus_huette.name,
 NULL,
 tim_haus_huette.info1 AS art,
 NULL,
 tim_haus_huette.info2 AS region,
 NULL,
 NULL,
 tim_haus_huette.geoloc,
 tim_haus_huette.symbolnummer
 FROM tim_haus_huette

UNION ALL

SELECT tim_museum.name,
 NULL,
 tim_museum.info1 AS art,
 NULL,
 NULL,
 NULL,
 tim_museum.kn AS name_lang,
 tim_museum.geoloc,
 tim_museum.symbolnummer
 FROM tim_museum

UNION ALL

... several other SELECTS (shortened because of stackoverflow restrictions)

UNION ALL

SELECT tim_wohnmobilstellplatz.name,
 NULL,
 NULL,
 NULL,
 NULL,
 NULL,
 NULL,
 tim_wohnmobilstellplatz.geoloc,
 tim_wohnmobilstellplatz.symbolnummer
 FROM tim_wohnmobilstellplatz


WITH DATA;

ALTER TABLE vt_views.poi_test
 OWNER TO postgres;

GRANT ALL ON TABLE vt_views.poi TO postgres;
GRANT ALL ON TABLE vt_views.poi TO PUBLIC;

Any Idea why that is? Is it because for example info1 is used three times? I can't edit the origin tables because we have a batch which is filling the tables. Thanks for you help!

1 Answers1

2

The issue is with the 1st query, for the NULL entries. You should name the corresponding columns:

SELECT tim_bergname.name,
 tim_bergname.info1 AS hoehe,
 NULL AS mycol1,
 NULL AS mycol2,
 tim_bergname.info2 AS region,
 NULL AS mycol3,
 NULL AS mycol4,
 tim_bergname.geoloc,
 tim_bergname.symbolnummer
 FROM tim_bergname
JGH
  • 15,928
  • 4
  • 31
  • 48