1

I'm working in Postgres 9.4. I have two tables:

                                      Table "public.parcel"
    Column    |          Type          |                            Modifiers
 ogc_fid      | integer                | not null default
 wkb_geometry | geometry(Polygon,4326) |
 county       | character varying      |
 parcel_area  | double precision       |

            Table "public.county"
 Column |          Type          | Modifiers
--------+------------------------+-----------
 name   | character(1)           |
 chull  | geometry(Polygon,4326) |
 area   | double precision       |

I would like to find all the unique values of county in parcel, and the total areas of the attached parcels, and then insert them into the county table as name and area respectively.

I know how to do the first half of this:

SELECT county, 
       SUM(parcel_area) AS area 
FROM inspire_parcel 
GROUP BY county;

But what I don't know is how to insert these values into county. Can anyone advise?

I think it's something like:

UPDATE county SET name, area = (SELECT county, SUM(parcel_area) AS area 
FROM inspire_parcel GROUP BY county)
0

1 Answer 1

2

You use INSERT INTO. So, something like this:

INSERT INTO county
 SELECT county, SUM(parcel_area) AS area
  FROM inspire_parcel GROUP BY county;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. That worked for me when I edited it slightly: INSERT INTO county(name, area)...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.