Commit f985acbd authored by Craig Earley's avatar Craig Earley
Browse files

fixed response table foreign keys and data types

parent ffdfcf89
......@@ -254,7 +254,7 @@ update call_type set category_id = call_category.cat_id from call_category where
-- -- agency processing: populate agency table, from those id's populate response table
insert into agency (agency_abbrev, agency_name) select distinct abbrev,name from response_csv;
insert into response (call_id, agency_id) select calls_csv.call_id, agency.agency_id from calls_csv inner join response_csv on response_csv.call_id=calls_csv.call_id inner join agency on response_csv.abbrev=agency.agency_abbrev;
insert into response (call_id, agency_id) select RIGHT(calls_csv.call_id,5)::integer, agency.agency_id from calls_csv inner join response_csv on response_csv.call_id=calls_csv.call_id inner join agency on response_csv.abbrev=agency.agency_abbrev;
update call_type set type_name=lower(type_name);
......
begin;
-- -- Create the tables
-- -- Create the raw data tables
create table calls_csv (call_id char(12) primary key,
date date, time time without time zone, complaint varchar,
address varchar, city varchar, lat real, long real );
create table response_csv (call_id char(12), abbrev varchar, name varchar);
-- -- Create the core tables
create table calls (call_id int primary key,
place_id real, date date, time time, type_name char(12));
create table place (place_id serial primary key,
addr varchar, lat real, long real, city varchar, state varchar);
create table agency (agency_id serial unique, agency_abbrev varchar, agency_name varchar, city varchar);
create table response (call_id int references calls(call_id), agency_id int references agency(agency_id));
-- -- agency hierarchy
create table agency_type (agency_id serial unique, type_name char(15));
-- -- incident hierarchy
create table call_type (complaint_name varchar, type_name char(12), category_id real);
......@@ -36,13 +44,6 @@ update call_category set group_id = call_group.group_id from call_group where ca
update call_category set group_id = call_group.group_id from call_group where call_group.group_name='law' and cat_name like 'law%';
update call_category set group_id = call_group.group_id from call_group where call_group.group_name='misc' and cat_name like 'misc%';
-- -- agency hierarchy
create table agency (agency_id serial unique, agency_abbrev varchar, agency_name varchar, city varchar);
create table agency_type (agency_id serial unique, type_name char(15));
-- -- agencies with their calls
create table response (call_id char(12), agency_id real);
-- -- create any useful views
commit;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment