-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add computed column to retrive naics code
- Loading branch information
Showing
4 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
schema/deploy/computed_columns/application_revision_naics_code.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
-- Deploy ggircs-portal:computed_columns/application_revision_naics_code to pg | ||
-- requires: tables/form_result | ||
-- requires: tables/application_revision | ||
|
||
begin; | ||
|
||
create or replace function ggircs_portal.application_revision_naics_code(app ggircs_portal.application_revision) | ||
returns ggircs_portal.naics_code as | ||
$function$ | ||
|
||
with x as ( | ||
select ((form_result.form_result ->> 'operator')::json ->> 'naics')::varchar(1000) as naics | ||
from ggircs_portal.form_result | ||
join ggircs_portal.form_json | ||
on form_result.form_id = form_json.id | ||
and form_json.slug in ('admin', 'admin-2018') | ||
and form_result.application_id = 1 | ||
and form_result.version_number = 1 | ||
) | ||
select * from ggircs_portal.naics_code where naics_code = (select naics from x); | ||
|
||
$function$ language sql stable; | ||
|
||
comment on function ggircs_portal.application_revision_naics_code(ggircs_portal.application_revision) is 'This computed column returns the associated naics_code table row for the application_revision passed in via the parameters'; | ||
|
||
commit; |
7 changes: 7 additions & 0 deletions
7
schema/revert/computed_columns/application_revision_naics_code.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- Revert ggircs-portal:computed_columns/application_revision_naics_code from pg | ||
|
||
begin; | ||
|
||
drop function ggircs_portal.application_revision_naics_code; | ||
|
||
commit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
schema/verify/computed_columns/application_revision_naics_code.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- Verify ggircs-portal:computed_columns/application_revision_naics_code on pg | ||
|
||
begin; | ||
|
||
select pg_get_functiondef('ggircs_portal.application_revision_naics_code(ggircs_portal.application_revision)'::regprocedure); | ||
|
||
rollback; |