From 2 tables insert the information of certain fields in another new table

1

my new table where I want to insert the data has these columns:

gid,cvegeo,nom_ent,nom_mun,nom_loc,longitud,latitud,altitud,geom

the other 2 tables have 200 columns, between the columns of these are called the same as the new table the name of my tables are loc_urb_spheric and loc_rur_spheric . My new table has the same type of data of the columns that I want to take

this is my query which does not work:

INSERT INTO locaciones gid,cvegeo,nom_ent,nom_mun,nom_loc,longitud,latitud,altitud,geom FROM ( SELECT a.gid,a.cvegeo,a.nom_ent,a.nom_mun,a.nom_loc,
a.longitud,a.latitud,a.altitud,a.geom from loc_rur_spheric a UNION SELECT b.gid,b.cvegeo,b.nom_ent,b.nom_mun,b.nom_loc,
b.longitud,b.latitud,b.altitud,b.geom from loc_urb_spheric b );
    
asked by Kevin Lincon 26.11.2016 в 20:49
source

1 answer

2

As the INSERT INTO documentation indicates, the correct syntax is

>
  INSERT INTO <tabla> (<columnas>)
      <query>

That is:

  INSERT INTO locaciones (gid, cvegeo, ... )
  SELECT a.gid,a.cvegeo,a.nom_ent,a.nom_mun,a.nom_loc,
              a.longitud,a.latitud,a.altitud,a.geom 
           FROM loc_rur_spheric a 
  UNION         
  SELECT  b.gid,b.cvegeo,b.nom_ent,b.nom_mun,b.nom_loc,
            b.longitud,b.latitud,b.altitud,b.geom 
  FROM loc_urb_spheric b 
    
answered by 26.11.2016 / 21:35
source