all: sql/$(EXTENSION)--$(EXTVERSION).sql sql/$(EXTENSION)--unpackaged--$(EXTVERSION).sql sql/$(EXTENSION)--$(EXTVERSION)--$(EXTVERSION)next.sql sql/$(EXTENSION)--$(EXTVERSION)next--$(EXTVERSION).sql sql_minor_upgrade
-sql/$(EXTENSION).sql: sql_bits/postgis.sql sql_bits/postgis_comments.sql sql_bits/rtpostgis.sql sql_bits/spatial_ref_sys_config_dump.sql sql_bits/raster_comments.sql sql_bits/spatial_ref_sys.sql
+sql/$(EXTENSION).sql: sql_bits/postgis.sql sql_bits/postgis_proc_set_search_path.sql sql_bits/postgis_comments.sql sql_bits/rtpostgis.sql sql_bits/rtpostgis_proc_set_search_path.sql sql_bits/spatial_ref_sys_config_dump.sql sql_bits/raster_comments.sql sql_bits/spatial_ref_sys.sql
mkdir -p sql
echo '\echo Use "CREATE EXTENSION $(EXTENSION)" to load this file. \quit' > $@
cat $^ >> $@
sql_bits/postgis_comments.sql: ../../doc/postgis_comments.sql
cp $< $@
+
+sql_bits/postgis_proc_set_search_path.sql: ../../postgis/postgis_proc_set_search_path.sql
+ cp $< $@
+
+sql_bits/rtpostgis_proc_set_search_path.sql: ../../raster/rt_pg/rtpostgis_proc_set_search_path.sql
+ cp $< $@
#strip BEGIN/COMMIT since these are not allowed in extensions
sql_bits/rtpostgis.sql: ../../raster/rt_pg/rtpostgis.sql
sql_bits/spatial_ref_sys_config_dump.sql: ../../spatial_ref_sys.sql ../../utils/create_spatial_ref_sys_config_dump.pl
../../utils/create_spatial_ref_sys_config_dump.pl $< > $@
-sql_bits/rtpostgis_upgrade.sql: ../../raster/rt_pg/rtpostgis_upgrade.sql
+sql_bits/rtpostgis_upgrade.sql: ../../raster/rt_pg/rtpostgis_upgrade.sql sql_bits/rtpostgis_proc_set_search_path.sql
$(PERL) -pe "s/BEGIN\;//g ; s/COMMIT\;//g; s/^(DROP .*)\;/SELECT postgis_extension_drop_if_exists('$(EXTENSION)', '\1');\n\1\;/" $< > $@
-sql_bits/postgis_upgrade.sql: ../../postgis/postgis_upgrade.sql
+sql_bits/postgis_upgrade.sql: ../../postgis/postgis_upgrade.sql sql_bits/postgis_proc_set_search_path.sql
$(PERL) -pe "s/BEGIN\;//g ; s/COMMIT\;//g; s/^(DROP .*)\;/SELECT postgis_extension_drop_if_exists('$(EXTENSION)', '\1');\n\1\;/" $< > $@
MODULEDIR=contrib/$(MODULE_big)
# Files to be copied to the contrib/ directory
-SQL_built=postgis.sql uninstall_postgis.sql postgis_upgrade.sql legacy.sql uninstall_legacy.sql legacy_minimal.sql legacy_gist.sql
+SQL_built=postgis.sql uninstall_postgis.sql postgis_upgrade.sql postgis_proc_set_search_path.sql legacy.sql uninstall_legacy.sql legacy_minimal.sql legacy_gist.sql
DATA=../spatial_ref_sys.sql
# SQL objects (files requiring pre-processing)
postgis_upgrade.sql.in: postgis.sql ../utils/postgis_proc_upgrade.pl
$(PERL) ../utils/postgis_proc_upgrade.pl $< UNUSED > $@
+
+postgis_proc_set_search_path.sql: postgis.sql ../utils/postgis_proc_set_search_path.pl
+ $(PERL) ../utils/postgis_proc_set_search_path.pl $< UNUSED > $@
postgis_upgrade.sql: postgis_drop_before.sql postgis_upgrade.sql.in postgis_drop_after.sql
echo "BEGIN;" > $@
MODULEDIR=contrib/postgis-@POSTGIS_MAJOR_VERSION@.@POSTGIS_MINOR_VERSION@
# Files to be copied to the contrib/ directory
-DATA_built=rtpostgis.sql rtpostgis_upgrade.sql uninstall_rtpostgis.sql rtpostgis_legacy.sql
+DATA_built=rtpostgis.sql rtpostgis_upgrade.sql rtpostgis_proc_set_search_path.sql uninstall_rtpostgis.sql rtpostgis_legacy.sql
DATA=
# SQL preprocessor
rtpostgis_upgrade.sql.in: rtpostgis.sql ../../utils/postgis_proc_upgrade.pl
$(PERL) ../../utils/postgis_proc_upgrade.pl $< UNUSED > $@
+
+rtpostgis_proc_set_search_path.sql: rtpostgis.sql ../../utils/postgis_proc_set_search_path.pl
+ $(PERL) ../../utils/postgis_proc_set_search_path.pl $< UNUSED > $@
rtpostgis_upgrade.sql: rtpostgis_upgrade_cleanup.sql rtpostgis_upgrade.sql.in rtpostgis_drop.sql
echo 'BEGIN;' > $@
# Load postgis.sql into the database
load_sql_file("${STAGED_SCRIPTS_DIR}/postgis.sql", 1);
load_sql_file("${STAGED_SCRIPTS_DIR}/postgis_comments.sql", 0);
+ load_sql_file("${STAGED_SCRIPTS_DIR}/postgis_proc_set_search_path.sql", 0);
if ( $OPT_WITH_TOPO )
{
print "Loading Raster into '${DB}'\n";
load_sql_file("${STAGED_SCRIPTS_DIR}/rtpostgis.sql", 1);
load_sql_file("${STAGED_SCRIPTS_DIR}/raster_comments.sql", 0);
+ load_sql_file("${STAGED_SCRIPTS_DIR}/rtpostgis_proc_set_search_path.sql", 0);
}
if ( $OPT_WITH_SFCGAL )
my $funchead = $1; #contains function header except the end )\r
my $endhead = 0;\r
my $endfunchead = $2;\r
+ my $search_path_safe = 0; # we can put a search path on it without disrupting spatial index use\r
if ($2 eq ')') ## reached end of header\r
{\r
$endhead = 1;\r
#strip off default args from the function header\r
$funchead =~ s/(default\s+[A-Za-z\.\+\-0-9\'\[\]\:\s]*)//ig;\r
\r
+ #check to see if function is STRICT or c or plpgsql\r
+ # we can't put search path on non-STRICT sql since search path breaks SQL inlining\r
+ # breaking sql inlining will break use of spatial index\r
+ my $endfunc = 0;\r
+ while(<INPUT>)\r
+ {\r
+ $endfunc = 1 if /^\s*(\$\$\s*)?LANGUAGE /i;\r
+ if ( $endfunc == 1 ){\r
+ $search_path_safe = 1 if /LANGUAGE\s+[\']*(c|plpgsql)/i;\r
+ $search_path_safe = 1 if /STRICT/i;\r
+ }\r
+ last if ( $endfunc && /\;/ );\r
+ }\r
\r
- print "EXECUTE 'ALTER FUNCTION $funchead $endfunchead SET search_path=' || quote_ident(param_postgis_schema) || ';';\n";\r
+ \r
+ if ($search_path_safe == 1)\r
+ {\r
+ print "EXECUTE 'ALTER FUNCTION $funchead $endfunchead SET search_path=' || quote_ident(param_postgis_schema) || ';';\n";\r
+ }\r
}\r
\r
}\r
\r
## End of DO\r
print 'END;';\r
-print '$$';\r
+print '$$;';\r
\r
__END__\r
\r