Skip to content

Commit

Permalink
set search path in functions
Browse files Browse the repository at this point in the history
  • Loading branch information
smnorris committed Nov 20, 2024
1 parent 7fee205 commit 1e28c41
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 2 deletions.
5 changes: 5 additions & 0 deletions db/functions/FWA_Downstream.sql
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ CREATE OR REPLACE FUNCTION whse_basemapping.FWA_Downstream(

RETURNS boolean AS $$

SET search_path TO public,whse_basemapping,usgs,hydrosheds;

SELECT
-- watershed code a is a descendant of watershed code b
wscode_ltree_a <@ wscode_ltree_b AND
Expand Down Expand Up @@ -108,6 +110,7 @@ CREATE OR REPLACE FUNCTION whse_basemapping.FWA_Downstream(
RETURNS boolean AS $$


SET search_path TO public,whse_basemapping,usgs,hydrosheds;

SELECT

Expand Down Expand Up @@ -203,6 +206,8 @@ CREATE OR REPLACE FUNCTION whse_basemapping.FWA_Downstream(

RETURNS boolean AS $$

SET search_path TO public,whse_basemapping,usgs,hydrosheds;

SELECT
whse_basemapping.FWA_Downstream(
blue_line_key_a,
Expand Down
2 changes: 2 additions & 0 deletions db/functions/FWA_DownstreamTrace.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ AS

$$

SET search_path TO public,whse_basemapping,usgs,hydrosheds;

DECLARE
v_blue_line_key integer := start_blue_line_key;
v_measure float := start_measure;
Expand Down
2 changes: 2 additions & 0 deletions db/functions/FWA_IndexPoint.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ AS

$$

SET search_path TO public,whse_basemapping,usgs,hydrosheds;

WITH pt AS

(
Expand Down
2 changes: 2 additions & 0 deletions db/functions/FWA_LocateAlong.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ DECLARE
v_measure float := downstream_route_measure;
v_geom geometry;

SET search_path TO public,whse_basemapping,usgs,hydrosheds;

BEGIN

RETURN QUERY
Expand Down
2 changes: 2 additions & 0 deletions db/functions/FWA_LocateAlongInterval.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ DECLARE
v_measure_max numeric;
v_measure_min numeric;

SET search_path TO public,whse_basemapping,usgs,hydrosheds;

BEGIN

-- find min and max measures of the stream
Expand Down
2 changes: 2 additions & 0 deletions db/functions/FWA_SliceWatershedAtPoint.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ CREATE OR REPLACE FUNCTION whse_basemapping.FWA_SliceWatershedAtPoint(blkey inte

RETURNS TABLE(wsds integer[], geom geometry) AS $$

SET search_path TO public,whse_basemapping,usgs,hydrosheds;

-- Generate a point from the privided blue line key and measure
WITH ref_point AS
(SELECT
Expand Down
3 changes: 3 additions & 0 deletions db/functions/FWA_StreamsAsMVT.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ RETURNS bytea
AS $$
DECLARE
result bytea;

SET search_path TO public,whse_basemapping,usgs,hydrosheds;

BEGIN
WITH

Expand Down
8 changes: 6 additions & 2 deletions db/functions/FWA_Upstream.sql
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ return TRUE when the values for b are upstream of the values for a.
*/

-- ensure the functions are created in the public schema
set search_path to public;

-- watershed code comparison only
CREATE OR REPLACE FUNCTION whse_basemapping.FWA_Upstream(
Expand All @@ -75,6 +73,8 @@ CREATE OR REPLACE FUNCTION whse_basemapping.FWA_Upstream(

RETURNS boolean AS $$

SET search_path TO public,whse_basemapping,usgs,hydrosheds;

SELECT
-- Simple case, where watershed code and local code of (a) are equivalent.
-- Return TRUE for all records in (b) that are children of (a)
Expand Down Expand Up @@ -132,6 +132,8 @@ CREATE OR REPLACE FUNCTION whse_basemapping.FWA_Upstream(

RETURNS boolean AS $$

SET search_path TO public,whse_basemapping,usgs,hydrosheds;

SELECT
-- b is a child of a, always
wscode_ltree_b <@ wscode_ltree_a AND
Expand Down Expand Up @@ -241,6 +243,8 @@ CREATE OR REPLACE FUNCTION whse_basemapping.FWA_Upstream(

RETURNS boolean AS $$

SET search_path TO public,whse_basemapping,usgs,hydrosheds;

SELECT
whse_basemapping.FWA_Upstream(
blue_line_key_a,
Expand Down
2 changes: 2 additions & 0 deletions db/functions/FWA_UpstreamBorderCrossings.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ RETURNS text

AS $$

SET search_path TO public,whse_basemapping,usgs,hydrosheds;

WITH local_segment AS
(
SELECT
Expand Down
2 changes: 2 additions & 0 deletions db/functions/FWA_UpstreamTrace.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ AS

$$

SET search_path TO public,whse_basemapping,usgs,hydrosheds;

DECLARE
v_blue_line_key integer := start_blue_line_key;
v_measure float := start_measure;
Expand Down
2 changes: 2 additions & 0 deletions db/functions/FWA_WatershedAtMeasure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ declare
v_blkey integer := blue_line_key;
v_measure float := downstream_route_measure;

SET search_path TO public,whse_basemapping,usgs,hydrosheds;

begin
if (
-- is provided location in a lake or a non-canal reservoir?
Expand Down
1 change: 1 addition & 0 deletions db/functions/FWA_WatershedHex.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ declare
v_blkey integer := blue_line_key;
v_measure float := downstream_route_measure;

SET search_path TO public,whse_basemapping,usgs,hydrosheds;

begin

Expand Down
1 change: 1 addition & 0 deletions db/functions/FWA_WatershedStream.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ declare
v_blkey integer := blue_line_key;
v_measure float := downstream_route_measure;

SET search_path TO public,whse_basemapping,usgs,hydrosheds;

begin

Expand Down
3 changes: 3 additions & 0 deletions db/functions/ST_Safe_Repair.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ create or replace function ST_Safe_Repair(
message text default '[unspecified]'
) returns geometry as
$$

SET search_path TO public,whse_basemapping,usgs,hydrosheds;

begin
if ST_IsEmpty(geom)
then
Expand Down
2 changes: 2 additions & 0 deletions db/functions/huc12.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ AS

$$

SET search_path TO public,whse_basemapping,usgs,hydrosheds;

WITH RECURSIVE walkup (huc12, geom) AS
(
SELECT huc12, wsd.geom
Expand Down
2 changes: 2 additions & 0 deletions db/functions/hydroshed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ AS

$$

SET search_path TO public,whse_basemapping,usgs,hydrosheds;

WITH RECURSIVE walkup (hybas_id, geom) AS
(
SELECT hybas_id, wsd.geom
Expand Down

0 comments on commit 1e28c41

Please sign in to comment.