Throw a useful error message if an extension script file is fed to psql.

We have seen one too many reports of people trying to use 9.1 extension
files in the old-fashioned way of sourcing them in psql.  Not only does
that usually not work (due to failure to substitute for MODULE_PATHNAME
and/or @extschema@), but if it did work they'd get a collection of loose
objects not an extension.  To prevent this, insert an \echo ... \quit
line that prints a suitable error message into each extension script file,
and teach commands/extension.c to ignore lines starting with \echo.
That should not only prevent any adverse consequences of loading a script
file the wrong way, but make it crystal clear to users that they need to
do it differently now.

Tom Lane, following an idea of Andrew Dunstan's.  Back-patch into 9.1
... there is not going to be much value in this if we wait till 9.2.
This commit is contained in:
Tom Lane 2011-10-12 15:45:03 -04:00
parent e0d273500a
commit 458857cc9d
78 changed files with 274 additions and 17 deletions

View File

@ -1,5 +1,8 @@
/* contrib/adminpack/adminpack--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION adminpack" to load this file. \quit
/* ***********************************************
* Administrative functions for PostgreSQL
* *********************************************** */

View File

@ -1,5 +1,8 @@
/* contrib/btree_gin/btree_gin--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION btree_gin" to load this file. \quit
CREATE FUNCTION gin_btree_consistent(internal, int2, anyelement, int4, internal, internal)
RETURNS bool
AS 'MODULE_PATHNAME'

View File

@ -1,5 +1,8 @@
/* contrib/btree_gin/btree_gin--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION btree_gin" to load this file. \quit
ALTER EXTENSION btree_gin ADD function gin_btree_consistent(internal,smallint,anyelement,integer,internal,internal);
ALTER EXTENSION btree_gin ADD function gin_extract_value_int2(smallint,internal);
ALTER EXTENSION btree_gin ADD function gin_compare_prefix_int2(smallint,smallint,smallint,internal);

View File

@ -1,5 +1,8 @@
/* contrib/btree_gist/btree_gist--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION btree_gist" to load this file. \quit
CREATE FUNCTION gbtreekey4_in(cstring)
RETURNS gbtreekey4
AS 'MODULE_PATHNAME', 'gbtreekey_in'

View File

@ -1,5 +1,8 @@
/* contrib/btree_gist/btree_gist--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION btree_gist" to load this file. \quit
ALTER EXTENSION btree_gist ADD type gbtreekey4;
ALTER EXTENSION btree_gist ADD function gbtreekey4_in(cstring);
ALTER EXTENSION btree_gist ADD function gbtreekey4_out(gbtreekey4);

View File

@ -1,5 +1,8 @@
/* contrib/chkpass/chkpass--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION chkpass" to load this file. \quit
--
-- Input and output functions and the type itself:
--

View File

@ -1,5 +1,8 @@
/* contrib/chkpass/chkpass--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION chkpass" to load this file. \quit
ALTER EXTENSION chkpass ADD type chkpass;
ALTER EXTENSION chkpass ADD function chkpass_in(cstring);
ALTER EXTENSION chkpass ADD function chkpass_out(chkpass);

View File

@ -1,5 +1,8 @@
/* contrib/citext/citext--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION citext" to load this file. \quit
--
-- PostgreSQL code for CITEXT.
--

View File

@ -1,5 +1,8 @@
/* contrib/citext/citext--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION citext" to load this file. \quit
ALTER EXTENSION citext ADD type citext;
ALTER EXTENSION citext ADD function citextin(cstring);
ALTER EXTENSION citext ADD function citextout(citext);

View File

@ -1,5 +1,8 @@
/* contrib/cube/cube--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION cube" to load this file. \quit
-- Create the user-defined type for N-dimensional boxes
CREATE FUNCTION cube_in(cstring)

View File

@ -1,5 +1,8 @@
/* contrib/cube/cube--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION cube" to load this file. \quit
ALTER EXTENSION cube ADD type cube;
ALTER EXTENSION cube ADD function cube_in(cstring);
ALTER EXTENSION cube ADD function cube(double precision[],double precision[]);

View File

@ -1,5 +1,8 @@
/* contrib/dblink/dblink--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION dblink" to load this file. \quit
-- dblink_connect now restricts non-superusers to password
-- authenticated connections
CREATE FUNCTION dblink_connect (text)

View File

@ -1,5 +1,8 @@
/* contrib/dblink/dblink--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION dblink" to load this file. \quit
ALTER EXTENSION dblink ADD function dblink_connect(text);
ALTER EXTENSION dblink ADD function dblink_connect(text,text);
ALTER EXTENSION dblink ADD function dblink_connect_u(text);

View File

@ -1,5 +1,8 @@
/* contrib/dict_int/dict_int--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION dict_int" to load this file. \quit
CREATE FUNCTION dintdict_init(internal)
RETURNS internal
AS 'MODULE_PATHNAME'

View File

@ -1,5 +1,8 @@
/* contrib/dict_int/dict_int--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION dict_int" to load this file. \quit
ALTER EXTENSION dict_int ADD function dintdict_init(internal);
ALTER EXTENSION dict_int ADD function dintdict_lexize(internal,internal,internal,internal);
ALTER EXTENSION dict_int ADD text search template intdict_template;

View File

@ -1,5 +1,8 @@
/* contrib/dict_xsyn/dict_xsyn--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION dict_xsyn" to load this file. \quit
CREATE FUNCTION dxsyn_init(internal)
RETURNS internal
AS 'MODULE_PATHNAME'

View File

@ -1,5 +1,8 @@
/* contrib/dict_xsyn/dict_xsyn--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION dict_xsyn" to load this file. \quit
ALTER EXTENSION dict_xsyn ADD function dxsyn_init(internal);
ALTER EXTENSION dict_xsyn ADD function dxsyn_lexize(internal,internal,internal,internal);
ALTER EXTENSION dict_xsyn ADD text search template xsyn_template;

View File

@ -1,5 +1,8 @@
/* contrib/earthdistance/earthdistance--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION earthdistance" to load this file. \quit
-- earth() returns the radius of the earth in meters. This is the only
-- place you need to change things for the cube base distance functions
-- in order to use different units (or a better value for the Earth's radius).

View File

@ -1,5 +1,8 @@
/* contrib/earthdistance/earthdistance--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION earthdistance" to load this file. \quit
ALTER EXTENSION earthdistance ADD function earth();
ALTER EXTENSION earthdistance ADD type earth;
ALTER EXTENSION earthdistance ADD function sec_to_gc(double precision);

View File

@ -1,5 +1,8 @@
/* contrib/file_fdw/file_fdw--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION file_fdw" to load this file. \quit
CREATE FUNCTION file_fdw_handler()
RETURNS fdw_handler
AS 'MODULE_PATHNAME'

View File

@ -1,5 +1,8 @@
/* contrib/fuzzystrmatch/fuzzystrmatch--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION fuzzystrmatch" to load this file. \quit
CREATE FUNCTION levenshtein (text,text) RETURNS int
AS 'MODULE_PATHNAME','levenshtein'
LANGUAGE C IMMUTABLE STRICT;

View File

@ -1,5 +1,8 @@
/* contrib/fuzzystrmatch/fuzzystrmatch--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION fuzzystrmatch" to load this file. \quit
ALTER EXTENSION fuzzystrmatch ADD function levenshtein(text,text);
ALTER EXTENSION fuzzystrmatch ADD function levenshtein(text,text,integer,integer,integer);
ALTER EXTENSION fuzzystrmatch ADD function metaphone(text,integer);

View File

@ -1,5 +1,8 @@
/* contrib/hstore/hstore--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION hstore" to load this file. \quit
CREATE TYPE hstore;
CREATE FUNCTION hstore_in(cstring)

View File

@ -1,5 +1,8 @@
/* contrib/hstore/hstore--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION hstore" to load this file. \quit
ALTER EXTENSION hstore ADD type hstore;
ALTER EXTENSION hstore ADD function hstore_in(cstring);
ALTER EXTENSION hstore ADD function hstore_out(hstore);

View File

@ -1,5 +1,8 @@
/* contrib/intagg/intagg--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION intagg" to load this file. \quit
-- Internal function for the aggregate
-- Is called for each item in an aggregation
CREATE FUNCTION int_agg_state (internal, int4)

View File

@ -1,5 +1,8 @@
/* contrib/intagg/intagg--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION intagg" to load this file. \quit
ALTER EXTENSION intagg ADD function int_agg_state(internal,integer);
ALTER EXTENSION intagg ADD function int_agg_final_array(internal);
ALTER EXTENSION intagg ADD function int_array_aggregate(integer);

View File

@ -1,5 +1,8 @@
/* contrib/intarray/intarray--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION intarray" to load this file. \quit
--
-- Create the user-defined type for the 1-D integer arrays (_int4)
--

View File

@ -1,5 +1,8 @@
/* contrib/intarray/intarray--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION intarray" to load this file. \quit
ALTER EXTENSION intarray ADD type query_int;
ALTER EXTENSION intarray ADD function bqarr_in(cstring);
ALTER EXTENSION intarray ADD function bqarr_out(query_int);

View File

@ -1,5 +1,8 @@
/* contrib/isn/isn--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION isn" to load this file. \quit
-- Example:
-- create table test ( id isbn );
-- insert into test values('978-0-393-04002-9');

View File

@ -1,5 +1,8 @@
/* contrib/isn/isn--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION isn" to load this file. \quit
ALTER EXTENSION isn ADD type ean13;
ALTER EXTENSION isn ADD function ean13_in(cstring);
ALTER EXTENSION isn ADD function ean13_out(ean13);

View File

@ -1,5 +1,8 @@
/* contrib/lo/lo--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION lo" to load this file. \quit
--
-- Create the data type ... now just a domain over OID
--

View File

@ -1,5 +1,8 @@
/* contrib/lo/lo--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION lo" to load this file. \quit
ALTER EXTENSION lo ADD domain lo;
ALTER EXTENSION lo ADD function lo_oid(lo);
ALTER EXTENSION lo ADD function lo_manage();

View File

@ -1,5 +1,8 @@
/* contrib/ltree/ltree--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION ltree" to load this file. \quit
CREATE FUNCTION ltree_in(cstring)
RETURNS ltree
AS 'MODULE_PATHNAME'

View File

@ -1,5 +1,8 @@
/* contrib/ltree/ltree--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION ltree" to load this file. \quit
ALTER EXTENSION ltree ADD type ltree;
ALTER EXTENSION ltree ADD function ltree_in(cstring);
ALTER EXTENSION ltree ADD function ltree_out(ltree);

View File

@ -1,5 +1,8 @@
/* contrib/pageinspect/pageinspect--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pageinspect" to load this file. \quit
--
-- get_raw_page()
--

View File

@ -1,5 +1,8 @@
/* contrib/pageinspect/pageinspect--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pageinspect" to load this file. \quit
DROP FUNCTION heap_page_items(bytea);
CREATE FUNCTION heap_page_items(IN page bytea,
OUT lp smallint,

View File

@ -1,5 +1,8 @@
/* contrib/pg_buffercache/pg_buffercache--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pg_buffercache" to load this file. \quit
-- Register the function.
CREATE FUNCTION pg_buffercache_pages()
RETURNS SETOF RECORD

View File

@ -1,4 +1,7 @@
/* contrib/pg_buffercache/pg_buffercache--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pg_buffercache" to load this file. \quit
ALTER EXTENSION pg_buffercache ADD function pg_buffercache_pages();
ALTER EXTENSION pg_buffercache ADD view pg_buffercache;

View File

@ -1,5 +1,8 @@
/* contrib/pg_freespacemap/pg_freespacemap--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pg_freespacemap" to load this file. \quit
-- Register the C function.
CREATE FUNCTION pg_freespace(regclass, bigint)
RETURNS int2

View File

@ -1,4 +1,7 @@
/* contrib/pg_freespacemap/pg_freespacemap--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pg_freespacemap" to load this file. \quit
ALTER EXTENSION pg_freespacemap ADD function pg_freespace(regclass,bigint);
ALTER EXTENSION pg_freespacemap ADD function pg_freespace(regclass);

View File

@ -1,5 +1,8 @@
/* contrib/pg_stat_statements/pg_stat_statements--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pg_stat_statements" to load this file. \quit
-- Register functions.
CREATE FUNCTION pg_stat_statements_reset()
RETURNS void

View File

@ -1,5 +1,8 @@
/* contrib/pg_stat_statements/pg_stat_statements--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pg_stat_statements" to load this file. \quit
ALTER EXTENSION pg_stat_statements ADD function pg_stat_statements_reset();
ALTER EXTENSION pg_stat_statements ADD function pg_stat_statements();
ALTER EXTENSION pg_stat_statements ADD view pg_stat_statements;

View File

@ -1,5 +1,8 @@
/* contrib/pg_trgm/pg_trgm--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pg_trgm" to load this file. \quit
CREATE FUNCTION set_limit(float4)
RETURNS float4
AS 'MODULE_PATHNAME'

View File

@ -1,5 +1,8 @@
/* contrib/pg_trgm/pg_trgm--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pg_trgm" to load this file. \quit
ALTER EXTENSION pg_trgm ADD function set_limit(real);
ALTER EXTENSION pg_trgm ADD function show_limit();
ALTER EXTENSION pg_trgm ADD function show_trgm(text);

View File

@ -1,5 +1,8 @@
/* contrib/pgcrypto/pgcrypto--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pgcrypto" to load this file. \quit
CREATE FUNCTION digest(text, text)
RETURNS bytea
AS 'MODULE_PATHNAME', 'pg_digest'

View File

@ -1,5 +1,8 @@
/* contrib/pgcrypto/pgcrypto--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pgcrypto" to load this file. \quit
ALTER EXTENSION pgcrypto ADD function digest(text,text);
ALTER EXTENSION pgcrypto ADD function digest(bytea,text);
ALTER EXTENSION pgcrypto ADD function hmac(text,text,text);

View File

@ -1,5 +1,8 @@
/* contrib/pgrowlocks/pgrowlocks--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pgrowlocks" to load this file. \quit
CREATE FUNCTION pgrowlocks(IN relname text,
OUT locked_row TID, -- row TID
OUT lock_type TEXT, -- lock type

View File

@ -1,3 +1,6 @@
/* contrib/pgrowlocks/pgrowlocks--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pgrowlocks" to load this file. \quit
ALTER EXTENSION pgrowlocks ADD function pgrowlocks(text);

View File

@ -1,5 +1,8 @@
/* contrib/pgstattuple/pgstattuple--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pgstattuple" to load this file. \quit
CREATE FUNCTION pgstattuple(IN relname text,
OUT table_len BIGINT, -- physical table length in bytes
OUT tuple_count BIGINT, -- number of live tuples

View File

@ -1,5 +1,8 @@
/* contrib/pgstattuple/pgstattuple--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pgstattuple" to load this file. \quit
ALTER EXTENSION pgstattuple ADD function pgstattuple(text);
ALTER EXTENSION pgstattuple ADD function pgstattuple(oid);
ALTER EXTENSION pgstattuple ADD function pgstatindex(text);

View File

@ -1,5 +1,8 @@
/* contrib/seg/seg--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION seg" to load this file. \quit
-- Create the user-defined type for 1-D floating point intervals (seg)
CREATE FUNCTION seg_in(cstring)

View File

@ -1,5 +1,8 @@
/* contrib/seg/seg--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION seg" to load this file. \quit
ALTER EXTENSION seg ADD type seg;
ALTER EXTENSION seg ADD function seg_in(cstring);
ALTER EXTENSION seg ADD function seg_out(seg);

View File

@ -1,5 +1,8 @@
/* contrib/spi/autoinc--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION autoinc" to load this file. \quit
CREATE FUNCTION autoinc()
RETURNS trigger
AS 'MODULE_PATHNAME'

View File

@ -1,3 +1,6 @@
/* contrib/spi/autoinc--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION autoinc" to load this file. \quit
ALTER EXTENSION autoinc ADD function autoinc();

View File

@ -1,5 +1,8 @@
/* contrib/spi/insert_username--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION insert_username" to load this file. \quit
CREATE FUNCTION insert_username()
RETURNS trigger
AS 'MODULE_PATHNAME'

View File

@ -1,3 +1,6 @@
/* contrib/spi/insert_username--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION insert_username" to load this file. \quit
ALTER EXTENSION insert_username ADD function insert_username();

View File

@ -1,5 +1,8 @@
/* contrib/spi/moddatetime--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION moddatetime" to load this file. \quit
CREATE FUNCTION moddatetime()
RETURNS trigger
AS 'MODULE_PATHNAME'

View File

@ -1,3 +1,6 @@
/* contrib/spi/moddatetime--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION moddatetime" to load this file. \quit
ALTER EXTENSION moddatetime ADD function moddatetime();

View File

@ -1,5 +1,8 @@
/* contrib/spi/refint--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION refint" to load this file. \quit
CREATE FUNCTION check_primary_key()
RETURNS trigger
AS 'MODULE_PATHNAME'

View File

@ -1,4 +1,7 @@
/* contrib/spi/refint--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION refint" to load this file. \quit
ALTER EXTENSION refint ADD function check_primary_key();
ALTER EXTENSION refint ADD function check_foreign_key();

View File

@ -1,5 +1,8 @@
/* contrib/spi/timetravel--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION timetravel" to load this file. \quit
CREATE FUNCTION timetravel()
RETURNS trigger
AS 'MODULE_PATHNAME'

View File

@ -1,5 +1,8 @@
/* contrib/spi/timetravel--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION timetravel" to load this file. \quit
ALTER EXTENSION timetravel ADD function timetravel();
ALTER EXTENSION timetravel ADD function set_timetravel(name,integer);
ALTER EXTENSION timetravel ADD function get_timetravel(name);

View File

@ -1,5 +1,8 @@
/* contrib/sslinfo/sslinfo--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION sslinfo" to load this file. \quit
CREATE FUNCTION ssl_client_serial() RETURNS numeric
AS 'MODULE_PATHNAME', 'ssl_client_serial'
LANGUAGE C STRICT;

View File

@ -1,5 +1,8 @@
/* contrib/sslinfo/sslinfo--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION sslinfo" to load this file. \quit
ALTER EXTENSION sslinfo ADD function ssl_client_serial();
ALTER EXTENSION sslinfo ADD function ssl_is_used();
ALTER EXTENSION sslinfo ADD function ssl_client_cert_present();

View File

@ -1,5 +1,8 @@
/* contrib/tablefunc/tablefunc--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION tablefunc" to load this file. \quit
CREATE FUNCTION normal_rand(int4, float8, float8)
RETURNS setof float8
AS 'MODULE_PATHNAME','normal_rand'

View File

@ -1,5 +1,8 @@
/* contrib/tablefunc/tablefunc--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION tablefunc" to load this file. \quit
ALTER EXTENSION tablefunc ADD function normal_rand(integer,double precision,double precision);
ALTER EXTENSION tablefunc ADD function crosstab(text);
ALTER EXTENSION tablefunc ADD type tablefunc_crosstab_2;

View File

@ -1,5 +1,8 @@
/* contrib/test_parser/test_parser--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION test_parser" to load this file. \quit
CREATE FUNCTION testprs_start(internal, int4)
RETURNS internal
AS 'MODULE_PATHNAME'

View File

@ -1,5 +1,8 @@
/* contrib/test_parser/test_parser--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION test_parser" to load this file. \quit
ALTER EXTENSION test_parser ADD function testprs_start(internal,integer);
ALTER EXTENSION test_parser ADD function testprs_getlexeme(internal,internal,internal);
ALTER EXTENSION test_parser ADD function testprs_end(internal);

View File

@ -1,5 +1,8 @@
/* contrib/tsearch2/tsearch2--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION tsearch2" to load this file. \quit
-- These domains are just to catch schema-qualified references to the
-- old data types.
CREATE DOMAIN tsvector AS pg_catalog.tsvector;

View File

@ -1,5 +1,8 @@
/* contrib/tsearch2/tsearch2--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION tsearch2" to load this file. \quit
ALTER EXTENSION tsearch2 ADD type @extschema@.tsvector;
ALTER EXTENSION tsearch2 ADD type @extschema@.tsquery;
ALTER EXTENSION tsearch2 ADD type @extschema@.gtsvector;

View File

@ -1,5 +1,8 @@
/* contrib/unaccent/unaccent--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION unaccent" to load this file. \quit
CREATE FUNCTION unaccent(regdictionary, text)
RETURNS text
AS 'MODULE_PATHNAME', 'unaccent_dict'

View File

@ -1,5 +1,8 @@
/* contrib/unaccent/unaccent--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION unaccent" to load this file. \quit
ALTER EXTENSION unaccent ADD function unaccent(regdictionary,text);
ALTER EXTENSION unaccent ADD function unaccent(text);
ALTER EXTENSION unaccent ADD function unaccent_init(internal);

View File

@ -1,5 +1,8 @@
/* contrib/uuid-ossp/uuid-ossp--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION uuid-ossp" to load this file. \quit
CREATE FUNCTION uuid_nil()
RETURNS uuid
AS 'MODULE_PATHNAME', 'uuid_nil'

View File

@ -1,5 +1,8 @@
/* contrib/uuid-ossp/uuid-ossp--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION uuid-ossp" to load this file. \quit
ALTER EXTENSION "uuid-ossp" ADD function uuid_nil();
ALTER EXTENSION "uuid-ossp" ADD function uuid_ns_dns();
ALTER EXTENSION "uuid-ossp" ADD function uuid_ns_url();

View File

@ -1,5 +1,8 @@
/* contrib/xml2/xml2--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION xml2" to load this file. \quit
--SQL for XML parser
-- deprecated old name for xml_is_well_formed

View File

@ -1,5 +1,8 @@
/* contrib/xml2/xml2--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION xml2" to load this file. \quit
ALTER EXTENSION xml2 ADD function xslt_process(text,text);
ALTER EXTENSION xml2 ADD function xslt_process(text,text,text);
ALTER EXTENSION xml2 ADD function xpath_table(text,text,text,text,text);

View File

@ -522,6 +522,17 @@
script files are implicitly executed within a transaction block.
</para>
<para>
An extension's <acronym>SQL</> script files can also contain lines
beginning with <literal>\echo</>, which will be ignored (treated as
comments) by the extension mechanism. This provision is commonly used
to throw an error if the script file is fed to <application>psql</>
rather than being loaded via <command>CREATE EXTENSION</> (see example
script below). Without that, users might accidentally load the
extension's contents as <quote>loose</> objects rather than as an
extension, a state of affairs that's a bit tedious to recover from.
</para>
<para>
While the script files can contain any characters allowed by the specified
encoding, control files should contain only plain ASCII, because there
@ -808,6 +819,9 @@ SELECT * FROM pg_extension_update_paths('<replaceable>extension_name</>');
The script file <filename>pair--1.0.sql</> looks like this:
<programlisting><![CDATA[
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pair" to load this file. \quit
CREATE TYPE pair AS ( k text, v text );
CREATE OR REPLACE FUNCTION pair(anyelement, text)

View File

@ -33,6 +33,7 @@
#include "catalog/indexing.h"
#include "catalog/namespace.h"
#include "catalog/objectaccess.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_depend.h"
#include "catalog/pg_extension.h"
#include "catalog/pg_namespace.h"
@ -855,26 +856,39 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
CurrentExtensionObject = extensionOid;
PG_TRY();
{
char *sql = read_extension_script_file(control, filename);
char *c_sql = read_extension_script_file(control, filename);
Datum t_sql;
/* We use various functions that want to operate on text datums */
t_sql = CStringGetTextDatum(c_sql);
/*
* Reduce any lines beginning with "\echo" to empty. This allows
* scripts to contain messages telling people not to run them via
* psql, which has been found to be necessary due to old habits.
*/
t_sql = DirectFunctionCall4Coll(textregexreplace,
C_COLLATION_OID,
t_sql,
CStringGetTextDatum("^\\\\echo.*$"),
CStringGetTextDatum(""),
CStringGetTextDatum("ng"));
/*
* If it's not relocatable, substitute the target schema name for
* occcurrences of @extschema@.
*
* For a relocatable extension, we just run the script as-is. There
* cannot be any need for @extschema@, else it wouldn't be
* relocatable.
* For a relocatable extension, we needn't do this. There cannot be
* any need for @extschema@, else it wouldn't be relocatable.
*/
if (!control->relocatable)
{
const char *qSchemaName = quote_identifier(schemaName);
sql = text_to_cstring(
DatumGetTextPP(
DirectFunctionCall3(replace_text,
CStringGetTextDatum(sql),
t_sql = DirectFunctionCall3(replace_text,
t_sql,
CStringGetTextDatum("@extschema@"),
CStringGetTextDatum(qSchemaName))));
CStringGetTextDatum(qSchemaName));
}
/*
@ -883,15 +897,16 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
*/
if (control->module_pathname)
{
sql = text_to_cstring(
DatumGetTextPP(
DirectFunctionCall3(replace_text,
CStringGetTextDatum(sql),
t_sql = DirectFunctionCall3(replace_text,
t_sql,
CStringGetTextDatum("MODULE_PATHNAME"),
CStringGetTextDatum(control->module_pathname))));
CStringGetTextDatum(control->module_pathname));
}
execute_sql_string(sql, filename);
/* And now back to C string */
c_sql = text_to_cstring(DatumGetTextPP(t_sql));
execute_sql_string(c_sql, filename);
}
PG_CATCH();
{