I've asked this question and I recieved an answer, which solve the problem but then I noticed there are duplicates in the polygons. Below is the query that creates the state line boundaries.
CREATE SEQUENCE polyseq_1; CREATE TABLE boundaries AS SELECT nextval('polyseq_1') AS id, b.name as state_name, a.dma_1 as dma_1, CASE WHEN ST_Within(a.geom,b.geom) THEN a.geom ELSE ST_Multi(ST_Intersection(a.geom,b.geom)) END AS geom FROM tl_2015_us_state_4326 b JOIN dma_boundary a ON ST_Intersects(a.geom, b.geom); CREATE TABLE boundaries_polygons AS SELECT * FROM (SELECT id, state_name, dma_1, (ST_Dump(b.geom)).geom from boundaries b) as temp WHERE ST_GeometryType(temp.geom) = 'ST_Polygon' ;
Below is the results, you can see that there are duplicates of the same DMA in the same state. Ideally, I'd like to merge all these polygons together into one by their name and state. For instance, combine all the Washington-DC DMA for Washignton, then all the Washington-DC DMAs for Virgina, and all the Washington-DC DMAs for Maryland into 3 distinct parts.