Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add index on geoid column for ACS db tables #261

Merged
merged 3 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion migrations/acs.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA IF NOT EXISTS acs;
DROP TABLE IF EXISTS acs.:"TABLE_NAME";
DROP INDEX IF EXISTS acs.:INDEX_NAME;

CREATE TEMP TABLE tmp (
census_geoid text,
Expand Down Expand Up @@ -28,4 +29,6 @@ SELECT
m as margin_of_error,
p as percent,
z as percent_margin_of_error
INTO acs.:"TABLE_NAME" FROM tmp;
INTO acs.:"TABLE_NAME" FROM tmp;

CREATE INDEX IF NOT EXISTS :INDEX_NAME ON acs.:"TABLE_NAME" (geoid);
5 changes: 4 additions & 1 deletion migrations/decennial.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CREATE SCHEMA IF NOT EXISTS decennial;
DROP TABLE IF EXISTS decennial.:"TABLE_NAME";
DROP INDEX IF EXISTS decennial.:INDEX_NAME;

CREATE TEMP TABLE tmp (
year text,
Expand All @@ -11,4 +12,6 @@ CREATE TEMP TABLE tmp (
\COPY tmp FROM PSTDIN WITH DELIMITER ',' CSV HEADER;

DROP TABLE IF EXISTS decennial.:"TABLE_NAME";
SELECT * INTO decennial.:"TABLE_NAME" FROM tmp;
SELECT * INTO decennial.:"TABLE_NAME" FROM tmp;

CREATE INDEX IF NOT EXISTS :INDEX_NAME ON decennial.:"TABLE_NAME" (geoid);
2 changes: 1 addition & 1 deletion migrations/etl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if [[ $download -eq 1 ]]; then
fi

if [[ $load -eq 1 ]]; then
cat $filepath | psql $DATABASE_URL -v TABLE_NAME=$year -f migrations/$datasource.sql
cat $filepath | psql $DATABASE_URL -v TABLE_NAME=$year -v INDEX_NAME="${datasource}_${year}_geoid_idx" -f migrations/$datasource.sql
fi

if [[ $clean -eq 1 ]]; then
Expand Down
Loading