Commit aa4c702e authored by Bruce Momjian's avatar Bruce Momjian

Update /contrib for "autocommit TO 'on'".

Create objects in public schema.

Make spacing/capitalization consistent.

Remove transaction block use for object creation.

Remove unneeded function GRANTs.
parent fb9bc342
#!/usr/bin/perl #!/usr/bin/perl
# $Id: adddepend,v 1.1 2002/09/18 20:38:59 momjian Exp $ # $Id: adddepend,v 1.2 2002/10/18 18:41:19 momjian Exp $
# Project exists to assist PostgreSQL users with their structural upgrade # Project exists to assist PostgreSQL users with their structural upgrade
# from 7.2 (or prior) to 7.3 (possibly later). Must be run against a 7.3 # from 7.2 (or prior) to 7.3 (possibly later). Must be run against a 7.3
...@@ -125,6 +125,20 @@ my $dbh = DBI->connect($dsn, $dbuser, $dbpass); ...@@ -125,6 +125,20 @@ my $dbh = DBI->connect($dsn, $dbuser, $dbpass);
# We want to control commits # We want to control commits
$dbh->{'AutoCommit'} = 0; $dbh->{'AutoCommit'} = 0;
# turn on autocommit
my $sql = qq{
SET search_path = public;
};
my $sth = $dbh->prepare($sql);
$sth->execute();
# turn on autocommit
my $sql2 = qq{
SET autocommit TO 'on';
};
my $sth2 = $dbh->prepare($sql2);
$sth2->execute();
END { END {
$dbh->disconnect() if $dbh; $dbh->disconnect() if $dbh;
} }
......
This diff is collapsed.
begin transaction;
-- Adjust this setting to control where the objects get created. -- Adjust this setting to control where the objects get created.
SET search_path = public; SET search_path = public;
SET autocommit TO 'on';
-- create type of int4 key -- create type of int4 key
CREATE FUNCTION int4key_in(cstring) CREATE FUNCTION int4key_in(cstring)
RETURNS int4key RETURNS int4key
AS 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
LANGUAGE 'c' with (isstrict); LANGUAGE 'c' WITH (isstrict);
CREATE FUNCTION int4key_out(int4key) CREATE FUNCTION int4key_out(int4key)
RETURNS cstring RETURNS cstring
AS 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
LANGUAGE 'c' with (isstrict); LANGUAGE 'c' WITH (isstrict);
CREATE TYPE int4key ( CREATE TYPE int4key (
internallength = 8, INTERNALLENGTH = 8,
input = int4key_in, INPUT = int4key_in,
output = int4key_out OUTPUT = int4key_out
); );
...@@ -29,23 +29,45 @@ output = int4key_out ...@@ -29,23 +29,45 @@ output = int4key_out
-- --
-- --
-- define the GiST support methods -- define the GiST support methods
create function gint4_consistent(internal,int4,int2) returns bool as 'MODULE_PATHNAME' language 'C'; CREATE FUNCTION gint4_consistent(internal,int4,int2)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
create function gint4_compress(internal) returns internal as 'MODULE_PATHNAME' language 'C'; CREATE FUNCTION gint4_compress(internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
create function btree_decompress(internal) returns internal as 'MODULE_PATHNAME' language 'C'; CREATE FUNCTION btree_decompress(internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
create function gint4_penalty(internal,internal,internal) returns internal as 'MODULE_PATHNAME' language 'C' with(isstrict); CREATE FUNCTION gint4_penalty(internal,internal,internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE 'C' WITH (isstrict);
create function gint4_picksplit(internal, internal) returns internal as 'MODULE_PATHNAME' language 'C'; CREATE FUNCTION gint4_picksplit(internal, internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
create function gint4_union(bytea, internal) returns int4 as 'MODULE_PATHNAME' language 'C'; CREATE FUNCTION gint4_union(bytea, internal)
RETURNS int4
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
create function gint4_same(internal, internal, internal) returns internal as 'MODULE_PATHNAME' language 'C'; CREATE FUNCTION gint4_same(internal, internal, internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
-- Create the operator class -- Create the operator class
CREATE OPERATOR CLASS gist_int4_ops CREATE OPERATOR CLASS gist_int4_ops
DEFAULT FOR TYPE int4 USING gist AS DEFAULT FOR TYPE int4 USING gist
AS
OPERATOR 1 < , OPERATOR 1 < ,
OPERATOR 2 <= , OPERATOR 2 <= ,
OPERATOR 3 = , OPERATOR 3 = ,
...@@ -73,34 +95,53 @@ CREATE OPERATOR CLASS gist_int4_ops ...@@ -73,34 +95,53 @@ CREATE OPERATOR CLASS gist_int4_ops
CREATE FUNCTION tskey_in(cstring) CREATE FUNCTION tskey_in(cstring)
RETURNS tskey RETURNS tskey
AS 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
LANGUAGE 'c' with (isstrict); LANGUAGE 'c' WITH (isstrict);
CREATE FUNCTION tskey_out(tskey) CREATE FUNCTION tskey_out(tskey)
RETURNS cstring RETURNS cstring
AS 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
LANGUAGE 'c' with (isstrict); LANGUAGE 'c' WITH (isstrict);
CREATE TYPE tskey ( CREATE TYPE tskey (
internallength = 16, INTERNALLENGTH = 16,
input = tskey_in, INPUT = tskey_in,
output = tskey_out OUTPUT = tskey_out
); );
create function gts_consistent(internal,timestamp,int2) returns bool as 'MODULE_PATHNAME' language 'C'; CREATE FUNCTION gts_consistent(internal,timestamp,int2)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
create function gts_compress(internal) returns internal as 'MODULE_PATHNAME' language 'C'; CREATE FUNCTION gts_compress(internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
create function gts_penalty(internal,internal,internal) returns internal as 'MODULE_PATHNAME' language 'C' with(isstrict); CREATE FUNCTION gts_penalty(internal,internal,internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE 'C' WITH (isstrict);
create function gts_picksplit(internal, internal) returns internal as 'MODULE_PATHNAME' language 'C'; CREATE FUNCTION gts_picksplit(internal, internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
create function gts_union(bytea, internal) returns int4 as 'MODULE_PATHNAME' language 'C'; CREATE FUNCTION gts_union(bytea, internal)
RETURNS int4
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
create function gts_same(internal, internal, internal) returns internal as 'MODULE_PATHNAME' language 'C'; CREATE FUNCTION gts_same(internal, internal, internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
-- Create the operator class -- Create the operator class
CREATE OPERATOR CLASS gist_timestamp_ops CREATE OPERATOR CLASS gist_timestamp_ops
DEFAULT FOR TYPE timestamp USING gist AS DEFAULT FOR TYPE timestamp USING gist
AS
OPERATOR 1 < , OPERATOR 1 < ,
OPERATOR 2 <= , OPERATOR 2 <= ,
OPERATOR 3 = , OPERATOR 3 = ,
...@@ -114,6 +155,3 @@ CREATE OPERATOR CLASS gist_timestamp_ops ...@@ -114,6 +155,3 @@ CREATE OPERATOR CLASS gist_timestamp_ops
FUNCTION 6 gts_picksplit (internal, internal), FUNCTION 6 gts_picksplit (internal, internal),
FUNCTION 7 gts_same (internal, internal, internal), FUNCTION 7 gts_same (internal, internal, internal),
STORAGE tskey; STORAGE tskey;
end transaction;
...@@ -7,35 +7,35 @@ psql:btree_gist.sql:10: WARNING: ProcedureCreate: type int4key is not yet defin ...@@ -7,35 +7,35 @@ psql:btree_gist.sql:10: WARNING: ProcedureCreate: type int4key is not yet defin
psql:btree_gist.sql:15: WARNING: Argument type "int4key" is only a shell psql:btree_gist.sql:15: WARNING: Argument type "int4key" is only a shell
psql:btree_gist.sql:76: WARNING: ProcedureCreate: type tskey is not yet defined psql:btree_gist.sql:76: WARNING: ProcedureCreate: type tskey is not yet defined
psql:btree_gist.sql:81: WARNING: Argument type "tskey" is only a shell psql:btree_gist.sql:81: WARNING: Argument type "tskey" is only a shell
create table inttmp (b int4); CREATE TABLE inttmp (b int4);
\copy inttmp from 'data/test_btree.data' \copy inttmp from 'data/test_btree.data'
create table tstmp ( t timestamp without time zone ); CREATE TABLE tstmp ( t timestamp without time zone );
\copy tstmp from 'data/test_btree_ts.data' \copy tstmp from 'data/test_btree_ts.data'
-- without idx -- without idx
select count(*) from inttmp where b <=10; SELECT count(*) FROM inttmp WHERE b <=10;
count count
------- -------
11 11
(1 row) (1 row)
select count(*) from tstmp where t < '2001-05-29 08:33:09'; SELECT count(*) FROM tstmp WHERE t < '2001-05-29 08:33:09';
count count
------- -------
66 66
(1 row) (1 row)
-- create idx -- create idx
create index aaaidx on inttmp using gist ( b ); CREATE INDEX aaaidx ON inttmp USING gist ( b );
create index tsidx on tstmp using gist ( t ); CREATE INDEX tsidx ON tstmp USING gist ( t );
--with idx --with idx
set enable_seqscan=off; SET enable_seqscan=off;
select count(*) from inttmp where b <=10; SELECT count(*) FROM inttmp WHERE b <=10;
count count
------- -------
11 11
(1 row) (1 row)
select count(*) from tstmp where t < '2001-05-29 08:33:09'; SELECT count(*) FROM tstmp WHERE t < '2001-05-29 08:33:09';
count count
------- -------
66 66
......
...@@ -3,34 +3,35 @@ ...@@ -3,34 +3,35 @@
-- does not depend on contents of seg.sql. -- does not depend on contents of seg.sql.
-- --
\set ECHO none \set ECHO none
SET autocommit TO 'on';
\i btree_gist.sql \i btree_gist.sql
\set ECHO all \set ECHO all
create table inttmp (b int4); CREATE TABLE inttmp (b int4);
\copy inttmp from 'data/test_btree.data' \copy inttmp from 'data/test_btree.data'
create table tstmp ( t timestamp without time zone ); CREATE TABLE tstmp ( t timestamp without time zone );
\copy tstmp from 'data/test_btree_ts.data' \copy tstmp from 'data/test_btree_ts.data'
-- without idx -- without idx
select count(*) from inttmp where b <=10; SELECT count(*) FROM inttmp WHERE b <=10;
select count(*) from tstmp where t < '2001-05-29 08:33:09'; SELECT count(*) FROM tstmp WHERE t < '2001-05-29 08:33:09';
-- create idx -- create idx
create index aaaidx on inttmp using gist ( b ); CREATE INDEX aaaidx ON inttmp USING gist ( b );
create index tsidx on tstmp using gist ( t ); CREATE INDEX tsidx ON tstmp USING gist ( t );
--with idx --with idx
set enable_seqscan=off; SET enable_seqscan=off;
select count(*) from inttmp where b <=10; SELECT count(*) FROM inttmp WHERE b <=10;
select count(*) from tstmp where t < '2001-05-29 08:33:09'; SELECT count(*) FROM tstmp WHERE t < '2001-05-29 08:33:09';
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
-- darcy@druid.net -- darcy@druid.net
-- http://www.druid.net/darcy/ -- http://www.druid.net/darcy/
-- --
-- $Header: /cvsroot/pgsql/contrib/chkpass/chkpass.sql.in,v 1.2 2002/08/22 00:01:38 tgl Exp $ -- $Header: /cvsroot/pgsql/contrib/chkpass/chkpass.sql.in,v 1.3 2002/10/18 18:41:19 momjian Exp $
-- --
-- best viewed with tabs set to 4 -- best viewed with tabs set to 4
-- --
...@@ -13,41 +13,46 @@ ...@@ -13,41 +13,46 @@
-- Input and output functions and the type itself: -- Input and output functions and the type itself:
-- --
create function chkpass_in(cstring) -- Adjust this setting to control where the objects get created.
returns chkpass SET search_path = public;
as 'MODULE_PATHNAME'
language 'c';
create function chkpass_out(chkpass) SET autocommit TO 'on';
returns cstring
as 'MODULE_PATHNAME'
language 'c';
create type chkpass ( CREATE FUNCTION chkpass_in(cstring)
RETURNS chkpass
AS 'MODULE_PATHNAME'
LANGUAGE 'c';
CREATE FUNCTION chkpass_out(chkpass)
RETURNS cstring
AS 'MODULE_PATHNAME'
LANGUAGE 'c';
CREATE TYPE chkpass (
internallength = 16, internallength = 16,
externallength = 13, externallength = 13,
input = chkpass_in, input = chkpass_in,
output = chkpass_out output = chkpass_out
); );
create function raw(chkpass) CREATE FUNCTION raw(chkpass)
returns text RETURNS text
as 'MODULE_PATHNAME', 'chkpass_rout' AS 'MODULE_PATHNAME', 'chkpass_rout'
language 'c'; LANGUAGE 'c';
-- --
-- The various boolean tests: -- The various boolean tests:
-- --
create function eq(chkpass, text) CREATE FUNCTION eq(chkpass, text)
returns bool RETURNS bool
as 'MODULE_PATHNAME', 'chkpass_eq' AS 'MODULE_PATHNAME', 'chkpass_eq'
language 'c'; LANGUAGE 'c';
create function ne(chkpass, text) CREATE FUNCTION ne(chkpass, text)
returns bool RETURNS bool
as 'MODULE_PATHNAME', 'chkpass_ne' AS 'MODULE_PATHNAME', 'chkpass_ne'
language 'c'; LANGUAGE 'c';
-- --
-- Now the operators. Note how some of the parameters to some -- Now the operators. Note how some of the parameters to some
...@@ -56,7 +61,7 @@ create function ne(chkpass, text) ...@@ -56,7 +61,7 @@ create function ne(chkpass, text)
-- will be implicitly defined when those are, further down. -- will be implicitly defined when those are, further down.
-- --
create operator = ( CREATE OPERATOR = (
leftarg = chkpass, leftarg = chkpass,
rightarg = text, rightarg = text,
commutator = =, commutator = =,
...@@ -64,7 +69,7 @@ create operator = ( ...@@ -64,7 +69,7 @@ create operator = (
procedure = eq procedure = eq
); );
create operator <> ( CREATE OPERATOR <> (
leftarg = chkpass, leftarg = chkpass,
rightarg = text, rightarg = text,
negator = =, negator = =,
......
This diff is collapsed.
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
-- does not depend on contents of cube.sql. -- does not depend on contents of cube.sql.
-- --
\set ECHO none \set ECHO none
psql:cube.sql:11: WARNING: ProcedureCreate: type cube is not yet defined psql:cube.sql:12: WARNING: ProcedureCreate: type cube is not yet defined
psql:cube.sql:16: WARNING: Argument type "cube" is only a shell psql:cube.sql:17: WARNING: Argument type "cube" is only a shell
-- --
-- testing the input and output functions -- testing the input and output functions
-- --
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
-- does not depend on contents of cube.sql. -- does not depend on contents of cube.sql.
-- --
\set ECHO none \set ECHO none
SET autocommit TO 'on';
\i cube.sql \i cube.sql
\set ECHO all \set ECHO all
......
...@@ -858,6 +858,10 @@ main(int argc, char **argv) ...@@ -858,6 +858,10 @@ main(int argc, char **argv)
exit(1); exit(1);
} }
PQexec(conn, "SET search_path = public");
PQexec(conn, "SET autocommit TO 'on'");
/* Substitute field names */ /* Substitute field names */
do_substitute(subarg, dbh); do_substitute(subarg, dbh);
......
-- Uncomment the following 9 lines to use original DEPRECATED functions --
--CREATE OR REPLACE FUNCTION dblink (text,text) RETURNS setof int -- Uncomment the following commented lines to use original DEPRECATED functions
-- AS 'MODULE_PATHNAME','dblink' LANGUAGE 'c' --
-- WITH (isstrict); --CREATE OR REPLACE FUNCTION dblink (text,text)
--CREATE OR REPLACE FUNCTION dblink_tok (int,int) RETURNS text --RETURNS setof int
-- AS 'MODULE_PATHNAME','dblink_tok' LANGUAGE 'c' --AS 'MODULE_PATHNAME','dblink'
-- WITH (isstrict); --LANGUAGE 'C' WITH (isstrict);
--CREATE OR REPLACE FUNCTION dblink_last_oid (int) RETURNS oid --CREATE OR REPLACE FUNCTION dblink_tok (int,int)
-- AS 'MODULE_PATHNAME','dblink_last_oid' LANGUAGE 'c' --RETURNS text
-- WITH (isstrict); --AS 'MODULE_PATHNAME','dblink_tok'
--LANGUAGE 'C' WITH (isstrict);
CREATE OR REPLACE FUNCTION dblink_connect (text) RETURNS text --CREATE OR REPLACE FUNCTION dblink_last_oid (int)
AS 'MODULE_PATHNAME','dblink_connect' LANGUAGE 'c' --RETURNS oid
WITH (isstrict); --AS 'MODULE_PATHNAME','dblink_last_oid'
--LANGUAGE 'C' WITH (isstrict);
CREATE OR REPLACE FUNCTION dblink_disconnect () RETURNS text
AS 'MODULE_PATHNAME','dblink_disconnect' LANGUAGE 'c' CREATE OR REPLACE FUNCTION dblink_connect (text)
WITH (isstrict); RETURNS text
AS 'MODULE_PATHNAME','dblink_connect'
CREATE OR REPLACE FUNCTION dblink_open (text,text) RETURNS text LANGUAGE 'C' WITH (isstrict);
AS 'MODULE_PATHNAME','dblink_open' LANGUAGE 'c'
WITH (isstrict); CREATE OR REPLACE FUNCTION dblink_disconnect ()
RETURNS text
CREATE OR REPLACE FUNCTION dblink_fetch (text,int) RETURNS setof record AS 'MODULE_PATHNAME','dblink_disconnect'
AS 'MODULE_PATHNAME','dblink_fetch' LANGUAGE 'c' LANGUAGE 'C' WITH (isstrict);
WITH (isstrict);
CREATE OR REPLACE FUNCTION dblink_open (text,text)
CREATE OR REPLACE FUNCTION dblink_close (text) RETURNS text RETURNS text
AS 'MODULE_PATHNAME','dblink_close' LANGUAGE 'c' AS 'MODULE_PATHNAME','dblink_open'
WITH (isstrict); LANGUAGE 'C' WITH (isstrict);
CREATE OR REPLACE FUNCTION dblink_fetch (text,int)
RETURNS setof record
AS 'MODULE_PATHNAME','dblink_fetch'
LANGUAGE 'C' WITH (isstrict);
CREATE OR REPLACE FUNCTION dblink_close (text)
RETURNS text
AS 'MODULE_PATHNAME','dblink_close'
LANGUAGE 'C' WITH (isstrict);
-- Note: if this is not a first time install of dblink, uncomment the -- Note: if this is not a first time install of dblink, uncomment the
-- following DROP which prepares the database for the new, non-deprecated -- following DROP which prepares the database for the new, non-deprecated
...@@ -35,55 +45,49 @@ CREATE OR REPLACE FUNCTION dblink_close (text) RETURNS text ...@@ -35,55 +45,49 @@ CREATE OR REPLACE FUNCTION dblink_close (text) RETURNS text
--DROP FUNCTION dblink (text,text); --DROP FUNCTION dblink (text,text);
-- Comment out the following 3 lines if the DEPRECATED functions are used. -- Comment out the following 3 lines if the DEPRECATED functions are used.
CREATE OR REPLACE FUNCTION dblink (text,text) RETURNS setof record CREATE OR REPLACE FUNCTION dblink (text,text)
AS 'MODULE_PATHNAME','dblink_record' LANGUAGE 'c' RETURNS setof record
WITH (isstrict); AS 'MODULE_PATHNAME','dblink_record'
LANGUAGE 'C' WITH (isstrict);
CREATE OR REPLACE FUNCTION dblink (text) RETURNS setof record
AS 'MODULE_PATHNAME','dblink_record' LANGUAGE 'c' CREATE OR REPLACE FUNCTION dblink (text)
WITH (isstrict); RETURNS setof record
AS 'MODULE_PATHNAME','dblink_record'
CREATE OR REPLACE FUNCTION dblink_exec (text,text) RETURNS text LANGUAGE 'C' WITH (isstrict);
AS 'MODULE_PATHNAME','dblink_exec' LANGUAGE 'c'
WITH (isstrict); CREATE OR REPLACE FUNCTION dblink_exec (text,text)
RETURNS text
CREATE OR REPLACE FUNCTION dblink_exec (text) RETURNS text AS 'MODULE_PATHNAME','dblink_exec'
AS 'MODULE_PATHNAME','dblink_exec' LANGUAGE 'c' LANGUAGE 'C' WITH (isstrict);
WITH (isstrict);
CREATE OR REPLACE FUNCTION dblink_exec (text)
RETURNS text
AS 'MODULE_PATHNAME','dblink_exec'
LANGUAGE 'c' WITH (isstrict);
CREATE TYPE dblink_pkey_results AS (position int4, colname text); CREATE TYPE dblink_pkey_results AS (position int4, colname text);
CREATE OR REPLACE FUNCTION dblink_get_pkey (text) RETURNS setof dblink_pkey_results CREATE OR REPLACE FUNCTION dblink_get_pkey (text)
AS 'MODULE_PATHNAME','dblink_get_pkey' LANGUAGE 'c' RETURNS setof dblink_pkey_results
WITH (isstrict); AS 'MODULE_PATHNAME','dblink_get_pkey'
LANGUAGE 'c' WITH (isstrict);
CREATE OR REPLACE FUNCTION dblink_build_sql_insert (text, int2vector, int4, _text, _text) RETURNS text
AS 'MODULE_PATHNAME','dblink_build_sql_insert' LANGUAGE 'c' CREATE OR REPLACE FUNCTION dblink_build_sql_insert (text, int2vector, int4, _text, _text)
WITH (isstrict); RETURNS text
AS 'MODULE_PATHNAME','dblink_build_sql_insert'
CREATE OR REPLACE FUNCTION dblink_build_sql_delete (text, int2vector, int4, _text) RETURNS text LANGUAGE 'C' WITH (isstrict);
AS 'MODULE_PATHNAME','dblink_build_sql_delete' LANGUAGE 'c'
WITH (isstrict); CREATE OR REPLACE FUNCTION dblink_build_sql_delete (text, int2vector, int4, _text)
RETURNS text
CREATE OR REPLACE FUNCTION dblink_build_sql_update (text, int2vector, int4, _text, _text) RETURNS text AS 'MODULE_PATHNAME','dblink_build_sql_delete'
AS 'MODULE_PATHNAME','dblink_build_sql_update' LANGUAGE 'c' LANGUAGE 'C' WITH (isstrict);
WITH (isstrict);
CREATE OR REPLACE FUNCTION dblink_build_sql_update (text, int2vector, int4, _text, _text)
CREATE OR REPLACE FUNCTION dblink_current_query () RETURNS text RETURNS text
AS 'MODULE_PATHNAME','dblink_current_query' LANGUAGE 'c'; AS 'MODULE_PATHNAME','dblink_build_sql_update'
LANGUAGE 'C' WITH (isstrict);
GRANT EXECUTE ON FUNCTION dblink_connect (text) TO PUBLIC;
GRANT EXECUTE ON FUNCTION dblink_disconnect () TO PUBLIC; CREATE OR REPLACE FUNCTION dblink_current_query ()
GRANT EXECUTE ON FUNCTION dblink_open (text,text) TO PUBLIC; RETURNS text
GRANT EXECUTE ON FUNCTION dblink_fetch (text,int) TO PUBLIC; AS 'MODULE_PATHNAME','dblink_current_query'
GRANT EXECUTE ON FUNCTION dblink_close (text) TO PUBLIC; LANGUAGE 'C';
GRANT EXECUTE ON FUNCTION dblink (text,text) TO PUBLIC;
GRANT EXECUTE ON FUNCTION dblink (text) TO PUBLIC;
GRANT EXECUTE ON FUNCTION dblink_exec (text,text) TO PUBLIC;
GRANT EXECUTE ON FUNCTION dblink_exec (text) TO PUBLIC;
GRANT EXECUTE ON FUNCTION dblink_get_pkey (text) TO PUBLIC;
GRANT EXECUTE ON FUNCTION dblink_build_sql_insert (text, int2vector, int4, _text, _text) TO PUBLIC;
GRANT EXECUTE ON FUNCTION dblink_build_sql_delete (text, int2vector, int4, _text) TO PUBLIC;
GRANT EXECUTE ON FUNCTION dblink_build_sql_update (text, int2vector, int4, _text, _text) TO PUBLIC;
GRANT EXECUTE ON FUNCTION dblink_current_query () TO PUBLIC;
...@@ -4,7 +4,11 @@ ...@@ -4,7 +4,11 @@
-- --
-- This initial hackery is to allow successive runs without failures. -- This initial hackery is to allow successive runs without failures.
-- --
CREATE OR REPLACE FUNCTION conditional_drop() RETURNS text AS ' -- Adjust this setting to control where the objects get created.
SET search_path = public;
SET autocommit TO 'on';
CREATE OR REPLACE FUNCTION conditional_drop()
RETURNS text AS '
DECLARE DECLARE
dbname text; dbname text;
BEGIN BEGIN
...@@ -26,28 +30,29 @@ CREATE DATABASE regression_slave; ...@@ -26,28 +30,29 @@ CREATE DATABASE regression_slave;
-- Turn off echoing so that expected file does not depend on -- Turn off echoing so that expected file does not depend on
-- contents of dblink.sql. -- contents of dblink.sql.
\set ECHO none \set ECHO none
create table foo(f1 int, f2 text, f3 text[], primary key (f1,f2)); CREATE TABLE foo(f1 int, f2 text, f3 text[], primary key (f1,f2));
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'foo_pkey' for table 'foo' NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'foo_pkey' for table 'foo'
insert into foo values(0,'a','{"a0","b0","c0"}'); INSERT INTO foo VALUES (0,'a','{"a0","b0","c0"}');
insert into foo values(1,'b','{"a1","b1","c1"}'); INSERT INTO foo VALUES (1,'b','{"a1","b1","c1"}');
insert into foo values(2,'c','{"a2","b2","c2"}'); INSERT INTO foo VALUES (2,'c','{"a2","b2","c2"}');
insert into foo values(3,'d','{"a3","b3","c3"}'); INSERT INTO foo VALUES (3,'d','{"a3","b3","c3"}');
insert into foo values(4,'e','{"a4","b4","c4"}'); INSERT INTO foo VALUES (4,'e','{"a4","b4","c4"}');
insert into foo values(5,'f','{"a5","b5","c5"}'); INSERT INTO foo VALUES (5,'f','{"a5","b5","c5"}');
insert into foo values(6,'g','{"a6","b6","c6"}'); INSERT INTO foo VALUES (6,'g','{"a6","b6","c6"}');
insert into foo values(7,'h','{"a7","b7","c7"}'); INSERT INTO foo VALUES (7,'h','{"a7","b7","c7"}');
insert into foo values(8,'i','{"a8","b8","c8"}'); INSERT INTO foo VALUES (8,'i','{"a8","b8","c8"}');
insert into foo values(9,'j','{"a9","b9","c9"}'); INSERT INTO foo VALUES (9,'j','{"a9","b9","c9"}');
-- misc utilities -- misc utilities
-- show the currently executing query -- show the currently executing query
select 'hello' as hello, dblink_current_query() as query; SELECT 'hello' AS hello, dblink_current_query() AS query;
hello | query hello | query
-------+----------------------------------------------------------- -------+-----------------------------------------------------------
hello | select 'hello' as hello, dblink_current_query() as query; hello | SELECT 'hello' AS hello, dblink_current_query() AS query;
(1 row) (1 row)
-- list the primary key fields -- list the primary key fields
select * from dblink_get_pkey('foo'); SELECT *
FROM dblink_get_pkey('foo');
position | colname position | colname
----------+--------- ----------+---------
1 | f1 1 | f1
...@@ -56,7 +61,7 @@ select * from dblink_get_pkey('foo'); ...@@ -56,7 +61,7 @@ select * from dblink_get_pkey('foo');
-- build an insert statement based on a local tuple, -- build an insert statement based on a local tuple,
-- replacing the primary key values with new ones -- replacing the primary key values with new ones
select dblink_build_sql_insert('foo','1 2',2,'{"0", "a"}','{"99", "xyz"}'); SELECT dblink_build_sql_insert('foo','1 2',2,'{"0", "a"}','{"99", "xyz"}');
dblink_build_sql_insert dblink_build_sql_insert
----------------------------------------------------------- -----------------------------------------------------------
INSERT INTO foo(f1,f2,f3) VALUES('99','xyz','{a0,b0,c0}') INSERT INTO foo(f1,f2,f3) VALUES('99','xyz','{a0,b0,c0}')
...@@ -64,14 +69,14 @@ select dblink_build_sql_insert('foo','1 2',2,'{"0", "a"}','{"99", "xyz"}'); ...@@ -64,14 +69,14 @@ select dblink_build_sql_insert('foo','1 2',2,'{"0", "a"}','{"99", "xyz"}');
-- build an update statement based on a local tuple, -- build an update statement based on a local tuple,
-- replacing the primary key values with new ones -- replacing the primary key values with new ones
select dblink_build_sql_update('foo','1 2',2,'{"0", "a"}','{"99", "xyz"}'); SELECT dblink_build_sql_update('foo','1 2',2,'{"0", "a"}','{"99", "xyz"}');
dblink_build_sql_update dblink_build_sql_update
---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------
UPDATE foo SET f1 = '99', f2 = 'xyz', f3 = '{a0,b0,c0}' WHERE f1 = '99' AND f2 = 'xyz' UPDATE foo SET f1 = '99', f2 = 'xyz', f3 = '{a0,b0,c0}' WHERE f1 = '99' AND f2 = 'xyz'
(1 row) (1 row)
-- build a delete statement based on a local tuple, -- build a delete statement based on a local tuple,
select dblink_build_sql_delete('foo','1 2',2,'{"0", "a"}'); SELECT dblink_build_sql_delete('foo','1 2',2,'{"0", "a"}');
dblink_build_sql_delete dblink_build_sql_delete
--------------------------------------------- ---------------------------------------------
DELETE FROM foo WHERE f1 = '0' AND f2 = 'a' DELETE FROM foo WHERE f1 = '0' AND f2 = 'a'
...@@ -85,7 +90,9 @@ select dblink_build_sql_delete('foo','1 2',2,'{"0", "a"}'); ...@@ -85,7 +90,9 @@ select dblink_build_sql_delete('foo','1 2',2,'{"0", "a"}');
\connect regression \connect regression
\set ECHO none \set ECHO none
-- regular old dblink -- regular old dblink
select * from dblink('dbname=regression_slave','select * from foo') as t(a int, b text, c text[]) where t.a > 7; SELECT *
FROM dblink('dbname=regression_slave','SELECT * FROM foo') AS t(a int, b text, c text[])
WHERE t.a > 7;
a | b | c a | b | c
---+---+------------ ---+---+------------
8 | i | {a8,b8,c8} 8 | i | {a8,b8,c8}
...@@ -93,17 +100,21 @@ select * from dblink('dbname=regression_slave','select * from foo') as t(a int, ...@@ -93,17 +100,21 @@ select * from dblink('dbname=regression_slave','select * from foo') as t(a int,
(2 rows) (2 rows)
-- should generate "no connection available" error -- should generate "no connection available" error
select * from dblink('select * from foo') as t(a int, b text, c text[]) where t.a > 7; SELECT *
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
WHERE t.a > 7;
ERROR: dblink: no connection available ERROR: dblink: no connection available
-- create a persistent connection -- create a persistent connection
select dblink_connect('dbname=regression_slave'); SELECT dblink_connect('dbname=regression_slave');
dblink_connect dblink_connect
---------------- ----------------
OK OK
(1 row) (1 row)
-- use the persistent connection -- use the persistent connection
select * from dblink('select * from foo') as t(a int, b text, c text[]) where t.a > 7; SELECT *
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
WHERE t.a > 7;
a | b | c a | b | c
---+---+------------ ---+---+------------
8 | i | {a8,b8,c8} 8 | i | {a8,b8,c8}
...@@ -111,14 +122,15 @@ select * from dblink('select * from foo') as t(a int, b text, c text[]) where t. ...@@ -111,14 +122,15 @@ select * from dblink('select * from foo') as t(a int, b text, c text[]) where t.
(2 rows) (2 rows)
-- open a cursor -- open a cursor
select dblink_open('rmt_foo_cursor','select * from foo'); SELECT dblink_open('rmt_foo_cursor','SELECT * FROM foo');
dblink_open dblink_open
------------- -------------
OK OK
(1 row) (1 row)
-- fetch some data -- fetch some data
select * from dblink_fetch('rmt_foo_cursor',4) as t(a int, b text, c text[]); SELECT *
FROM dblink_fetch('rmt_foo_cursor',4) AS t(a int, b text, c text[]);
a | b | c a | b | c
---+---+------------ ---+---+------------
0 | a | {a0,b0,c0} 0 | a | {a0,b0,c0}
...@@ -127,7 +139,8 @@ select * from dblink_fetch('rmt_foo_cursor',4) as t(a int, b text, c text[]); ...@@ -127,7 +139,8 @@ select * from dblink_fetch('rmt_foo_cursor',4) as t(a int, b text, c text[]);
3 | d | {a3,b3,c3} 3 | d | {a3,b3,c3}
(4 rows) (4 rows)
select * from dblink_fetch('rmt_foo_cursor',4) as t(a int, b text, c text[]); SELECT *
FROM dblink_fetch('rmt_foo_cursor',4) AS t(a int, b text, c text[]);
a | b | c a | b | c
---+---+------------ ---+---+------------
4 | e | {a4,b4,c4} 4 | e | {a4,b4,c4}
...@@ -137,7 +150,8 @@ select * from dblink_fetch('rmt_foo_cursor',4) as t(a int, b text, c text[]); ...@@ -137,7 +150,8 @@ select * from dblink_fetch('rmt_foo_cursor',4) as t(a int, b text, c text[]);
(4 rows) (4 rows)
-- this one only finds two rows left -- this one only finds two rows left
select * from dblink_fetch('rmt_foo_cursor',4) as t(a int, b text, c text[]); SELECT *
FROM dblink_fetch('rmt_foo_cursor',4) AS t(a int, b text, c text[]);
a | b | c a | b | c
---+---+------------ ---+---+------------
8 | i | {a8,b8,c8} 8 | i | {a8,b8,c8}
...@@ -145,35 +159,38 @@ select * from dblink_fetch('rmt_foo_cursor',4) as t(a int, b text, c text[]); ...@@ -145,35 +159,38 @@ select * from dblink_fetch('rmt_foo_cursor',4) as t(a int, b text, c text[]);
(2 rows) (2 rows)
-- close the cursor -- close the cursor
select dblink_close('rmt_foo_cursor'); SELECT dblink_close('rmt_foo_cursor');
dblink_close dblink_close
-------------- --------------
OK OK
(1 row) (1 row)
-- should generate "cursor rmt_foo_cursor does not exist" error -- should generate "cursor rmt_foo_cursor does not exist" error
select * from dblink_fetch('rmt_foo_cursor',4) as t(a int, b text, c text[]); SELECT *
FROM dblink_fetch('rmt_foo_cursor',4) AS t(a int, b text, c text[]);
ERROR: dblink_fetch: cursor rmt_foo_cursor does not exist ERROR: dblink_fetch: cursor rmt_foo_cursor does not exist
-- close the persistent connection -- close the persistent connection
select dblink_disconnect(); SELECT dblink_disconnect();
dblink_disconnect dblink_disconnect
------------------- -------------------
OK OK
(1 row) (1 row)
-- should generate "no connection available" error -- should generate "no connection available" error
select * from dblink('select * from foo') as t(a int, b text, c text[]) where t.a > 7; SELECT *
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
WHERE t.a > 7;
ERROR: dblink: no connection available ERROR: dblink: no connection available
-- put more data into our slave table, first using arbitrary connection syntax -- put more data into our slave table, first using arbitrary connection syntax
-- but truncate the actual return value so we can use diff to check for success -- but truncate the actual return value so we can use diff to check for success
select substr(dblink_exec('dbname=regression_slave','insert into foo values(10,''k'',''{"a10","b10","c10"}'')'),1,6); SELECT substr(dblink_exec('dbname=regression_slave','INSERT INTO foo VALUES (10,''k'',''{"a10","b10","c10"}'')'),1,6);
substr substr
-------- --------
INSERT INSERT
(1 row) (1 row)
-- create a persistent connection -- create a persistent connection
select dblink_connect('dbname=regression_slave'); SELECT dblink_connect('dbname=regression_slave');
dblink_connect dblink_connect
---------------- ----------------
OK OK
...@@ -181,14 +198,15 @@ select dblink_connect('dbname=regression_slave'); ...@@ -181,14 +198,15 @@ select dblink_connect('dbname=regression_slave');
-- put more data into our slave table, using persistent connection syntax -- put more data into our slave table, using persistent connection syntax
-- but truncate the actual return value so we can use diff to check for success -- but truncate the actual return value so we can use diff to check for success
select substr(dblink_exec('insert into foo values(11,''l'',''{"a11","b11","c11"}'')'),1,6); SELECT substr(dblink_exec('INSERT INTO foo VALUES (11,''l'',''{"a11","b11","c11"}'')'),1,6);
substr substr
-------- --------
INSERT INSERT
(1 row) (1 row)
-- let's see it -- let's see it
select * from dblink('select * from foo') as t(a int, b text, c text[]); SELECT *
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[]);
a | b | c a | b | c
----+---+--------------- ----+---+---------------
0 | a | {a0,b0,c0} 0 | a | {a0,b0,c0}
...@@ -206,34 +224,38 @@ select * from dblink('select * from foo') as t(a int, b text, c text[]); ...@@ -206,34 +224,38 @@ select * from dblink('select * from foo') as t(a int, b text, c text[]);
(12 rows) (12 rows)
-- change some data -- change some data
select dblink_exec('update foo set f3[2] = ''b99'' where f1 = 11'); SELECT dblink_exec('UPDATE foo SET f3[2] = ''b99'' WHERE f1 = 11');
dblink_exec dblink_exec
------------- -------------
UPDATE 1 UPDATE 1
(1 row) (1 row)
-- let's see it -- let's see it
select * from dblink('select * from foo') as t(a int, b text, c text[]) where a = 11; SELECT *
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
WHERE a = 11;
a | b | c a | b | c
----+---+--------------- ----+---+---------------
11 | l | {a11,b99,c11} 11 | l | {a11,b99,c11}
(1 row) (1 row)
-- delete some data -- delete some data
select dblink_exec('delete from foo where f1 = 11'); SELECT dblink_exec('DELETE FROM foo WHERE f1 = 11');
dblink_exec dblink_exec
------------- -------------
DELETE 1 DELETE 1
(1 row) (1 row)
-- let's see it -- let's see it
select * from dblink('select * from foo') as t(a int, b text, c text[]) where a = 11; SELECT *
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
WHERE a = 11;
a | b | c a | b | c
---+---+--- ---+---+---
(0 rows) (0 rows)
-- close the persistent connection -- close the persistent connection
select dblink_disconnect(); SELECT dblink_disconnect();
dblink_disconnect dblink_disconnect
------------------- -------------------
OK OK
......
...@@ -4,7 +4,14 @@ ...@@ -4,7 +4,14 @@
-- --
-- This initial hackery is to allow successive runs without failures. -- This initial hackery is to allow successive runs without failures.
-- --
CREATE OR REPLACE FUNCTION conditional_drop() RETURNS text AS '
-- Adjust this setting to control where the objects get created.
SET search_path = public;
SET autocommit TO 'on';
CREATE OR REPLACE FUNCTION conditional_drop()
RETURNS text AS '
DECLARE DECLARE
dbname text; dbname text;
BEGIN BEGIN
...@@ -26,36 +33,37 @@ CREATE DATABASE regression_slave; ...@@ -26,36 +33,37 @@ CREATE DATABASE regression_slave;
\i dblink.sql \i dblink.sql
\set ECHO all \set ECHO all
create table foo(f1 int, f2 text, f3 text[], primary key (f1,f2)); CREATE TABLE foo(f1 int, f2 text, f3 text[], primary key (f1,f2));
insert into foo values(0,'a','{"a0","b0","c0"}'); INSERT INTO foo VALUES (0,'a','{"a0","b0","c0"}');
insert into foo values(1,'b','{"a1","b1","c1"}'); INSERT INTO foo VALUES (1,'b','{"a1","b1","c1"}');
insert into foo values(2,'c','{"a2","b2","c2"}'); INSERT INTO foo VALUES (2,'c','{"a2","b2","c2"}');
insert into foo values(3,'d','{"a3","b3","c3"}'); INSERT INTO foo VALUES (3,'d','{"a3","b3","c3"}');
insert into foo values(4,'e','{"a4","b4","c4"}'); INSERT INTO foo VALUES (4,'e','{"a4","b4","c4"}');
insert into foo values(5,'f','{"a5","b5","c5"}'); INSERT INTO foo VALUES (5,'f','{"a5","b5","c5"}');
insert into foo values(6,'g','{"a6","b6","c6"}'); INSERT INTO foo VALUES (6,'g','{"a6","b6","c6"}');
insert into foo values(7,'h','{"a7","b7","c7"}'); INSERT INTO foo VALUES (7,'h','{"a7","b7","c7"}');
insert into foo values(8,'i','{"a8","b8","c8"}'); INSERT INTO foo VALUES (8,'i','{"a8","b8","c8"}');
insert into foo values(9,'j','{"a9","b9","c9"}'); INSERT INTO foo VALUES (9,'j','{"a9","b9","c9"}');
-- misc utilities -- misc utilities
-- show the currently executing query -- show the currently executing query
select 'hello' as hello, dblink_current_query() as query; SELECT 'hello' AS hello, dblink_current_query() AS query;
-- list the primary key fields -- list the primary key fields
select * from dblink_get_pkey('foo'); SELECT *
FROM dblink_get_pkey('foo');
-- build an insert statement based on a local tuple, -- build an insert statement based on a local tuple,
-- replacing the primary key values with new ones -- replacing the primary key values with new ones
select dblink_build_sql_insert('foo','1 2',2,'{"0", "a"}','{"99", "xyz"}'); SELECT dblink_build_sql_insert('foo','1 2',2,'{"0", "a"}','{"99", "xyz"}');
-- build an update statement based on a local tuple, -- build an update statement based on a local tuple,
-- replacing the primary key values with new ones -- replacing the primary key values with new ones
select dblink_build_sql_update('foo','1 2',2,'{"0", "a"}','{"99", "xyz"}'); SELECT dblink_build_sql_update('foo','1 2',2,'{"0", "a"}','{"99", "xyz"}');
-- build a delete statement based on a local tuple, -- build a delete statement based on a local tuple,
select dblink_build_sql_delete('foo','1 2',2,'{"0", "a"}'); SELECT dblink_build_sql_delete('foo','1 2',2,'{"0", "a"}');
-- --
-- Connect back to the regression database and define the functions. -- Connect back to the regression database and define the functions.
...@@ -68,64 +76,82 @@ select dblink_build_sql_delete('foo','1 2',2,'{"0", "a"}'); ...@@ -68,64 +76,82 @@ select dblink_build_sql_delete('foo','1 2',2,'{"0", "a"}');
\set ECHO all \set ECHO all
-- regular old dblink -- regular old dblink
select * from dblink('dbname=regression_slave','select * from foo') as t(a int, b text, c text[]) where t.a > 7; SELECT *
FROM dblink('dbname=regression_slave','SELECT * FROM foo') AS t(a int, b text, c text[])
WHERE t.a > 7;
-- should generate "no connection available" error -- should generate "no connection available" error
select * from dblink('select * from foo') as t(a int, b text, c text[]) where t.a > 7; SELECT *
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
WHERE t.a > 7;
-- create a persistent connection -- create a persistent connection
select dblink_connect('dbname=regression_slave'); SELECT dblink_connect('dbname=regression_slave');
-- use the persistent connection -- use the persistent connection
select * from dblink('select * from foo') as t(a int, b text, c text[]) where t.a > 7; SELECT *
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
WHERE t.a > 7;
-- open a cursor -- open a cursor
select dblink_open('rmt_foo_cursor','select * from foo'); SELECT dblink_open('rmt_foo_cursor','SELECT * FROM foo');
-- fetch some data -- fetch some data
select * from dblink_fetch('rmt_foo_cursor',4) as t(a int, b text, c text[]); SELECT *
select * from dblink_fetch('rmt_foo_cursor',4) as t(a int, b text, c text[]); FROM dblink_fetch('rmt_foo_cursor',4) AS t(a int, b text, c text[]);
SELECT *
FROM dblink_fetch('rmt_foo_cursor',4) AS t(a int, b text, c text[]);
-- this one only finds two rows left -- this one only finds two rows left
select * from dblink_fetch('rmt_foo_cursor',4) as t(a int, b text, c text[]); SELECT *
FROM dblink_fetch('rmt_foo_cursor',4) AS t(a int, b text, c text[]);
-- close the cursor -- close the cursor
select dblink_close('rmt_foo_cursor'); SELECT dblink_close('rmt_foo_cursor');
-- should generate "cursor rmt_foo_cursor does not exist" error -- should generate "cursor rmt_foo_cursor does not exist" error
select * from dblink_fetch('rmt_foo_cursor',4) as t(a int, b text, c text[]); SELECT *
FROM dblink_fetch('rmt_foo_cursor',4) AS t(a int, b text, c text[]);
-- close the persistent connection -- close the persistent connection
select dblink_disconnect(); SELECT dblink_disconnect();
-- should generate "no connection available" error -- should generate "no connection available" error
select * from dblink('select * from foo') as t(a int, b text, c text[]) where t.a > 7; SELECT *
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
WHERE t.a > 7;
-- put more data into our slave table, first using arbitrary connection syntax -- put more data into our slave table, first using arbitrary connection syntax
-- but truncate the actual return value so we can use diff to check for success -- but truncate the actual return value so we can use diff to check for success
select substr(dblink_exec('dbname=regression_slave','insert into foo values(10,''k'',''{"a10","b10","c10"}'')'),1,6); SELECT substr(dblink_exec('dbname=regression_slave','INSERT INTO foo VALUES(10,''k'',''{"a10","b10","c10"}'')'),1,6);
-- create a persistent connection -- create a persistent connection
select dblink_connect('dbname=regression_slave'); SELECT dblink_connect('dbname=regression_slave');
-- put more data into our slave table, using persistent connection syntax -- put more data into our slave table, using persistent connection syntax
-- but truncate the actual return value so we can use diff to check for success -- but truncate the actual return value so we can use diff to check for success
select substr(dblink_exec('insert into foo values(11,''l'',''{"a11","b11","c11"}'')'),1,6); SELECT substr(dblink_exec('INSERT INTO foo VALUES(11,''l'',''{"a11","b11","c11"}'')'),1,6);
-- let's see it -- let's see it
select * from dblink('select * from foo') as t(a int, b text, c text[]); SELECT *
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[]);
-- change some data -- change some data
select dblink_exec('update foo set f3[2] = ''b99'' where f1 = 11'); SELECT dblink_exec('UPDATE foo SET f3[2] = ''b99'' WHERE f1 = 11');
-- let's see it -- let's see it
select * from dblink('select * from foo') as t(a int, b text, c text[]) where a = 11; SELECT *
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
WHERE a = 11;
-- delete some data -- delete some data
select dblink_exec('delete from foo where f1 = 11'); SELECT dblink_exec('DELETE FROM foo WHERE f1 = 11');
-- let's see it -- let's see it
select * from dblink('select * from foo') as t(a int, b text, c text[]) where a = 11; SELECT *
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
WHERE a = 11;
-- close the persistent connection -- close the persistent connection
select dblink_disconnect(); SELECT dblink_disconnect();
-- Adjust this setting to control where the objects get created.
SET search_path = public;
CREATE TRIGGER "MyTableName_Trig" AFTER INSERT OR DELETE OR UPDATE SET autocommit TO 'on';
ON "MyTableName" FOR EACH ROW EXECUTE PROCEDURE
"recordchange" (); CREATE TRIGGER "MyTableName_Trig"
AFTER INSERT OR DELETE OR UPDATE ON "MyTableName"
FOR EACH ROW EXECUTE PROCEDURE "recordchange" ();
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
############################################################################## ##############################################################################
# $Id: DBMirror.pl,v 1.1 2002/06/23 21:58:07 momjian Exp $ # $Id: DBMirror.pl,v 1.2 2002/10/18 18:41:19 momjian Exp $
# #
############################################################################## ##############################################################################
...@@ -112,6 +112,23 @@ sub Main() { ...@@ -112,6 +112,23 @@ sub Main() {
die; die;
} }
my $setQuery;
$setQuery = "SET search_path = public";
$setResult = $masterConn->exec($setQuery);
if($setResult->resultStatus!=PGRES_COMMAND_OK) {
logErrorMessage($masterConn->errorMessage . "\n" .
$setQuery);
die;
}
my $setQuery2;
$setQuery2 = "SET autocommit TO 'on'";
$setResult2 = $masterConn->exec($setQuery2);
if($setResult2->resultStatus!=PGRES_COMMAND_OK) {
logErrorMessage($masterConn->errorMessage . "\n" .
$setQuery2);
die;
}
my $firstTime = 1; my $firstTime = 1;
while(1) { while(1) {
...@@ -127,6 +144,7 @@ sub Main() { ...@@ -127,6 +144,7 @@ sub Main() {
sendQueryToSlaves(undef,"SET autocommit TO 'on'");
sendQueryToSlaves(undef,"SET TRANSACTION ISOLATION LEVEL SERIALIZABLE"); sendQueryToSlaves(undef,"SET TRANSACTION ISOLATION LEVEL SERIALIZABLE");
sendQueryToSlaves(undef,"SET CONSTRAINTS ALL DEFERRED"); sendQueryToSlaves(undef,"SET CONSTRAINTS ALL DEFERRED");
...@@ -703,7 +721,7 @@ sub openSlaveConnection($) { ...@@ -703,7 +721,7 @@ sub openSlaveConnection($) {
$slaveConn = Pg::connectdb($slaveConnString); $slaveConn = Pg::connectdb($slaveConnString);
if($slaveConn->status !=PGRES_CONNECTION_OK) { if($slaveConn->status != PGRES_CONNECTION_OK) {
my $errorMessage = "Can't connect to slave database " ; my $errorMessage = "Can't connect to slave database " ;
$errorMessage .= $slavePtr->{"slaveHost"} . "\n"; $errorMessage .= $slavePtr->{"slaveHost"} . "\n";
$errorMessage .= $slaveConn->errorMessage; $errorMessage .= $slaveConn->errorMessage;
......
SET autocommit TO 'on';
CREATE FUNCTION "recordchange" () RETURNS trigger AS CREATE FUNCTION "recordchange" () RETURNS trigger AS
'/usr/local/pgsql/lib/pending.so', 'recordchange' LANGUAGE 'C'; '/usr/local/pgsql/lib/pending.so', 'recordchange' LANGUAGE 'C';
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
############################################################################## ##############################################################################
# $Id: clean_pending.pl,v 1.1 2002/06/23 21:58:08 momjian Exp $ # $Id: clean_pending.pl,v 1.2 2002/10/18 18:41:19 momjian Exp $
############################################################################## ##############################################################################
...@@ -69,6 +69,10 @@ unless($dbConn->status == PGRES_CONNECTION_OK) { ...@@ -69,6 +69,10 @@ unless($dbConn->status == PGRES_CONNECTION_OK) {
printf("Can't connect to database\n"); printf("Can't connect to database\n");
die; die;
} }
my $setresult = $dbConn->exec("SET autocommit TO 'on'");
unless($setresult->resultStatus == PGRES_COMMAND_OK) {
die $dbConn->errorMessage;
}
my $result = $dbConn->exec("BEGIN"); my $result = $dbConn->exec("BEGIN");
unless($result->resultStatus == PGRES_COMMAND_OK) { unless($result->resultStatus == PGRES_COMMAND_OK) {
die $dbConn->errorMessage; die $dbConn->errorMessage;
......
begin; -- Adjust this setting to control where the objects get created.
SET search_path = public;
SET autocommit TO 'on';
--------------- geo_distance --------------- geo_distance
CREATE OR REPLACE FUNCTION geo_distance (point, point) RETURNS float8 CREATE OR REPLACE FUNCTION geo_distance (point, point)
LANGUAGE 'c' IMMUTABLE STRICT AS 'MODULE_PATHNAME'; RETURNS float8
LANGUAGE 'C' IMMUTABLE STRICT AS 'MODULE_PATHNAME';
--------------- geo_distance as operator <@> --------------- geo_distance as operator <@>
CREATE OPERATOR <@> ( CREATE OPERATOR <@> (
leftarg = point, LEFTARG = point,
rightarg = point, RIGHTARG = point,
procedure = geo_distance, PROCEDURE = geo_distance,
commutator = <@> COMMUTATOR = <@>
); );
--
-- By default this function is made executable by anyone. To restrict
-- access by default, comment out the following grant command.
--
grant execute on function geo_distance(point, point) to public;
commit;
...@@ -9,73 +9,73 @@ ...@@ -9,73 +9,73 @@
-- --
-- Test getting the distance between two points using geo_distance. -- Test getting the distance between two points using geo_distance.
-- --
select geo_distance('(0,0)'::point,'(0,0)'::point)::numeric(20,5); SELECT geo_distance('(0,0)'::point,'(0,0)'::point)::numeric(20,5);
geo_distance geo_distance
-------------- --------------
0.00000 0.00000
(1 row) (1 row)
select geo_distance('(0,0)'::point,'(180,0)'::point)::numeric(20,5); SELECT geo_distance('(0,0)'::point,'(180,0)'::point)::numeric(20,5);
geo_distance geo_distance
-------------- --------------
12436.77274 12436.77274
(1 row) (1 row)
select geo_distance('(0,0)'::point,'(0,90)'::point)::numeric(20,5); SELECT geo_distance('(0,0)'::point,'(0,90)'::point)::numeric(20,5);
geo_distance geo_distance
-------------- --------------
6218.38637 6218.38637
(1 row) (1 row)
select geo_distance('(0,0)'::point,'(90,0)'::point)::numeric(20,5); SELECT geo_distance('(0,0)'::point,'(90,0)'::point)::numeric(20,5);
geo_distance geo_distance
-------------- --------------
6218.38637 6218.38637
(1 row) (1 row)
select geo_distance('(0,0)'::point,'(1,0)'::point)::numeric(20,5); SELECT geo_distance('(0,0)'::point,'(1,0)'::point)::numeric(20,5);
geo_distance geo_distance
-------------- --------------
69.09318 69.09318
(1 row) (1 row)
select geo_distance('(0,0)'::point,'(0,1)'::point)::numeric(20,5); SELECT geo_distance('(0,0)'::point,'(0,1)'::point)::numeric(20,5);
geo_distance geo_distance
-------------- --------------
69.09318 69.09318
(1 row) (1 row)
select geo_distance('(0,30)'::point,'(1,30)'::point)::numeric(20,5); SELECT geo_distance('(0,30)'::point,'(1,30)'::point)::numeric(20,5);
geo_distance geo_distance
-------------- --------------
59.83626 59.83626
(1 row) (1 row)
select geo_distance('(0,30)'::point,'(0,31)'::point)::numeric(20,5); SELECT geo_distance('(0,30)'::point,'(0,31)'::point)::numeric(20,5);
geo_distance geo_distance
-------------- --------------
69.09318 69.09318
(1 row) (1 row)
select geo_distance('(0,60)'::point,'(1,60)'::point)::numeric(20,5); SELECT geo_distance('(0,60)'::point,'(1,60)'::point)::numeric(20,5);
geo_distance geo_distance
-------------- --------------
34.54626 34.54626
(1 row) (1 row)
select geo_distance('(0,60)'::point,'(0,61)'::point)::numeric(20,5); SELECT geo_distance('(0,60)'::point,'(0,61)'::point)::numeric(20,5);
geo_distance geo_distance
-------------- --------------
69.09318 69.09318
(1 row) (1 row)
select geo_distance('(87.6,41.8)'::point,'(106.7,35.1)'::point)::numeric(20,5); SELECT geo_distance('(87.6,41.8)'::point,'(106.7,35.1)'::point)::numeric(20,5);
geo_distance geo_distance
-------------- --------------
1129.18983 1129.18983
(1 row) (1 row)
select (geo_distance('(87.6,41.8)'::point,'(106.7,35.1)'::point)*5280.*12.*2.54/100.)::numeric(20,5); SELECT (geo_distance('(87.6,41.8)'::point,'(106.7,35.1)'::point)*5280.*12.*2.54/100.)::numeric(20,5);
numeric numeric
--------------- ---------------
1817254.87730 1817254.87730
...@@ -84,73 +84,73 @@ select (geo_distance('(87.6,41.8)'::point,'(106.7,35.1)'::point)*5280.*12.*2.54/ ...@@ -84,73 +84,73 @@ select (geo_distance('(87.6,41.8)'::point,'(106.7,35.1)'::point)*5280.*12.*2.54/
-- --
-- Test getting the distance between two points using the <@> operator. -- Test getting the distance between two points using the <@> operator.
-- --
select ('(0,0)'::point <@> '(0,0)'::point)::numeric(20,5); SELECT ('(0,0)'::point <@> '(0,0)'::point)::numeric(20,5);
numeric numeric
--------- ---------
0.00000 0.00000
(1 row) (1 row)
select ('(0,0)'::point <@> '(180,0)'::point)::numeric(20,5); SELECT ('(0,0)'::point <@> '(180,0)'::point)::numeric(20,5);
numeric numeric
------------- -------------
12436.77274 12436.77274
(1 row) (1 row)
select ('(0,0)'::point <@> '(0,90)'::point)::numeric(20,5); SELECT ('(0,0)'::point <@> '(0,90)'::point)::numeric(20,5);
numeric numeric
------------ ------------
6218.38637 6218.38637
(1 row) (1 row)
select ('(0,0)'::point <@> '(90,0)'::point)::numeric(20,5); SELECT ('(0,0)'::point <@> '(90,0)'::point)::numeric(20,5);
numeric numeric
------------ ------------
6218.38637 6218.38637
(1 row) (1 row)
select ('(0,0)'::point <@> '(1,0)'::point)::numeric(20,5); SELECT ('(0,0)'::point <@> '(1,0)'::point)::numeric(20,5);
numeric numeric
---------- ----------
69.09318 69.09318
(1 row) (1 row)
select ('(0,0)'::point <@> '(0,1)'::point)::numeric(20,5); SELECT ('(0,0)'::point <@> '(0,1)'::point)::numeric(20,5);
numeric numeric
---------- ----------
69.09318 69.09318
(1 row) (1 row)
select ('(0,30)'::point <@> '(1,30)'::point)::numeric(20,5); SELECT ('(0,30)'::point <@> '(1,30)'::point)::numeric(20,5);
numeric numeric
---------- ----------
59.83626 59.83626
(1 row) (1 row)
select ('(0,30)'::point <@> '(0,31)'::point)::numeric(20,5); SELECT ('(0,30)'::point <@> '(0,31)'::point)::numeric(20,5);
numeric numeric
---------- ----------
69.09318 69.09318
(1 row) (1 row)
select ('(0,60)'::point <@> '(1,60)'::point)::numeric(20,5); SELECT ('(0,60)'::point <@> '(1,60)'::point)::numeric(20,5);
numeric numeric
---------- ----------
34.54626 34.54626
(1 row) (1 row)
select ('(0,60)'::point <@> '(0,61)'::point)::numeric(20,5); SELECT ('(0,60)'::point <@> '(0,61)'::point)::numeric(20,5);
numeric numeric
---------- ----------
69.09318 69.09318
(1 row) (1 row)
select ('(87.6,41.8)'::point <@> '(106.7,35.1)'::point)::numeric(20,5); SELECT ('(87.6,41.8)'::point <@> '(106.7,35.1)'::point)::numeric(20,5);
numeric numeric
------------ ------------
1129.18983 1129.18983
(1 row) (1 row)
select (('(87.6,41.8)'::point <@> '(106.7,35.1)'::point)*5280.*12.*2.54/100.)::numeric(20,5); SELECT (('(87.6,41.8)'::point <@> '(106.7,35.1)'::point)*5280.*12.*2.54/100.)::numeric(20,5);
numeric numeric
--------------- ---------------
1817254.87730 1817254.87730
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
-- does not depend on contents of earthdistance.sql or cube.sql. -- does not depend on contents of earthdistance.sql or cube.sql.
-- --
\set ECHO none \set ECHO none
SET autocommit TO 'on';
\i earthdistance.sql \i earthdistance.sql
\set ECHO all \set ECHO all
...@@ -14,32 +15,32 @@ ...@@ -14,32 +15,32 @@
-- Test getting the distance between two points using geo_distance. -- Test getting the distance between two points using geo_distance.
-- --
select geo_distance('(0,0)'::point,'(0,0)'::point)::numeric(20,5); SELECT geo_distance('(0,0)'::point,'(0,0)'::point)::numeric(20,5);
select geo_distance('(0,0)'::point,'(180,0)'::point)::numeric(20,5); SELECT geo_distance('(0,0)'::point,'(180,0)'::point)::numeric(20,5);
select geo_distance('(0,0)'::point,'(0,90)'::point)::numeric(20,5); SELECT geo_distance('(0,0)'::point,'(0,90)'::point)::numeric(20,5);
select geo_distance('(0,0)'::point,'(90,0)'::point)::numeric(20,5); SELECT geo_distance('(0,0)'::point,'(90,0)'::point)::numeric(20,5);
select geo_distance('(0,0)'::point,'(1,0)'::point)::numeric(20,5); SELECT geo_distance('(0,0)'::point,'(1,0)'::point)::numeric(20,5);
select geo_distance('(0,0)'::point,'(0,1)'::point)::numeric(20,5); SELECT geo_distance('(0,0)'::point,'(0,1)'::point)::numeric(20,5);
select geo_distance('(0,30)'::point,'(1,30)'::point)::numeric(20,5); SELECT geo_distance('(0,30)'::point,'(1,30)'::point)::numeric(20,5);
select geo_distance('(0,30)'::point,'(0,31)'::point)::numeric(20,5); SELECT geo_distance('(0,30)'::point,'(0,31)'::point)::numeric(20,5);
select geo_distance('(0,60)'::point,'(1,60)'::point)::numeric(20,5); SELECT geo_distance('(0,60)'::point,'(1,60)'::point)::numeric(20,5);
select geo_distance('(0,60)'::point,'(0,61)'::point)::numeric(20,5); SELECT geo_distance('(0,60)'::point,'(0,61)'::point)::numeric(20,5);
select geo_distance('(87.6,41.8)'::point,'(106.7,35.1)'::point)::numeric(20,5); SELECT geo_distance('(87.6,41.8)'::point,'(106.7,35.1)'::point)::numeric(20,5);
select (geo_distance('(87.6,41.8)'::point,'(106.7,35.1)'::point)*5280.*12.*2.54/100.)::numeric(20,5); SELECT (geo_distance('(87.6,41.8)'::point,'(106.7,35.1)'::point)*5280.*12.*2.54/100.)::numeric(20,5);
-- --
-- Test getting the distance between two points using the <@> operator. -- Test getting the distance between two points using the <@> operator.
-- --
select ('(0,0)'::point <@> '(0,0)'::point)::numeric(20,5); SELECT ('(0,0)'::point <@> '(0,0)'::point)::numeric(20,5);
select ('(0,0)'::point <@> '(180,0)'::point)::numeric(20,5); SELECT ('(0,0)'::point <@> '(180,0)'::point)::numeric(20,5);
select ('(0,0)'::point <@> '(0,90)'::point)::numeric(20,5); SELECT ('(0,0)'::point <@> '(0,90)'::point)::numeric(20,5);
select ('(0,0)'::point <@> '(90,0)'::point)::numeric(20,5); SELECT ('(0,0)'::point <@> '(90,0)'::point)::numeric(20,5);
select ('(0,0)'::point <@> '(1,0)'::point)::numeric(20,5); SELECT ('(0,0)'::point <@> '(1,0)'::point)::numeric(20,5);
select ('(0,0)'::point <@> '(0,1)'::point)::numeric(20,5); SELECT ('(0,0)'::point <@> '(0,1)'::point)::numeric(20,5);
select ('(0,30)'::point <@> '(1,30)'::point)::numeric(20,5); SELECT ('(0,30)'::point <@> '(1,30)'::point)::numeric(20,5);
select ('(0,30)'::point <@> '(0,31)'::point)::numeric(20,5); SELECT ('(0,30)'::point <@> '(0,31)'::point)::numeric(20,5);
select ('(0,60)'::point <@> '(1,60)'::point)::numeric(20,5); SELECT ('(0,60)'::point <@> '(1,60)'::point)::numeric(20,5);
select ('(0,60)'::point <@> '(0,61)'::point)::numeric(20,5); SELECT ('(0,60)'::point <@> '(0,61)'::point)::numeric(20,5);
select ('(87.6,41.8)'::point <@> '(106.7,35.1)'::point)::numeric(20,5); SELECT ('(87.6,41.8)'::point <@> '(106.7,35.1)'::point)::numeric(20,5);
select (('(87.6,41.8)'::point <@> '(106.7,35.1)'::point)*5280.*12.*2.54/100.)::numeric(20,5); SELECT (('(87.6,41.8)'::point <@> '(106.7,35.1)'::point)*5280.*12.*2.54/100.)::numeric(20,5);
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright 2002 by PostgreSQL Global Development Group * Copyright 2002 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/contrib/findoidjoins/Attic/findoidjoins.c,v 1.18 2002/09/05 19:57:32 tgl Exp $ * $Header: /cvsroot/pgsql/contrib/findoidjoins/Attic/findoidjoins.c,v 1.19 2002/10/18 18:41:20 momjian Exp $
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
...@@ -48,6 +48,8 @@ main(int argc, char **argv) ...@@ -48,6 +48,8 @@ main(int argc, char **argv)
resetPQExpBuffer(&sql); resetPQExpBuffer(&sql);
appendPQExpBuffer(&sql, "%s", appendPQExpBuffer(&sql, "%s",
"SET search_path = public;"
"SET autocommit TO 'on';"
"SELECT c.relname, (SELECT nspname FROM " "SELECT c.relname, (SELECT nspname FROM "
"pg_catalog.pg_namespace n WHERE n.oid = c.relnamespace) AS nspname " "pg_catalog.pg_namespace n WHERE n.oid = c.relnamespace) AS nspname "
"FROM pg_catalog.pg_class c " "FROM pg_catalog.pg_class c "
......
...@@ -166,6 +166,8 @@ sub main { ...@@ -166,6 +166,8 @@ sub main {
return 1; return 1;
} }
PQexec($PG_CONN, "SET search_path = public");
PQexec($PG_CONN, "SET autocommit TO 'on'");
PQexec($PG_CONN, "begin"); PQexec($PG_CONN, "begin");
$query = "declare C cursor for select (\""; $query = "declare C cursor for select (\"";
......
-- Adjust this setting to control where the objects get created.
SET search_path = public;
SET autocommit TO 'on';
CREATE OR REPLACE FUNCTION fti() RETURNS trigger AS CREATE OR REPLACE FUNCTION fti() RETURNS trigger AS
'MODULE_PATHNAME', 'fti' 'MODULE_PATHNAME', 'fti'
LANGUAGE 'C' VOLATILE CALLED ON NULL INPUT; LANGUAGE 'C' VOLATILE CALLED ON NULL INPUT;
GRANT EXECUTE ON FUNCTION fti() TO PUBLIC;
-- Adjust this setting to control where the objects get created.
SET search_path = public;
SET autocommit TO 'on';
DROP FUNCTION fti() CASCADE; DROP FUNCTION fti() CASCADE;
CREATE FUNCTION levenshtein (text,text) RETURNS int -- Adjust this setting to control where the objects get created.
AS 'MODULE_PATHNAME','levenshtein' LANGUAGE 'c' with (iscachable, isstrict); SET search_path = public;
CREATE FUNCTION metaphone (text,int) RETURNS text SET autocommit TO 'on';
AS 'MODULE_PATHNAME','metaphone' LANGUAGE 'c' with (iscachable, isstrict);
CREATE FUNCTION levenshtein (text,text)
RETURNS int
AS 'MODULE_PATHNAME','levenshtein'
LANGUAGE 'C' WITH (iscachable, isstrict);
CREATE FUNCTION metaphone (text,int)
RETURNS text
AS 'MODULE_PATHNAME','metaphone'
LANGUAGE 'C' WITH (iscachable, isstrict);
CREATE FUNCTION soundex(text) RETURNS text CREATE FUNCTION soundex(text) RETURNS text
AS 'MODULE_PATHNAME', 'soundex' LANGUAGE 'c' with (iscachable, isstrict); AS 'MODULE_PATHNAME', 'soundex'
LANGUAGE 'C' WITH (iscachable, isstrict);
CREATE FUNCTION text_soundex(text) RETURNS text CREATE FUNCTION text_soundex(text) RETURNS text
AS 'MODULE_PATHNAME', 'soundex' LANGUAGE 'c'; AS 'MODULE_PATHNAME', 'soundex'
LANGUAGE 'C';
GRANT EXECUTE ON FUNCTION levenshtein (text,text) TO PUBLIC;
GRANT EXECUTE ON FUNCTION metaphone (text,int) TO PUBLIC;
GRANT EXECUTE ON FUNCTION soundex(text) TO PUBLIC;
GRANT EXECUTE ON FUNCTION text_soundex(text) TO PUBLIC;
-- Drop functions -- Adjust this setting to control where the objects get created.
drop aggregate int_array_aggregate(int4); SET search_path = public;
drop function int_agg_state (int4, int4);
drop function int_agg_final_array (int4);
drop function int_array_enum (int4[]);
SET autocommit TO 'on';
-- Internal function for the aggregate -- Internal function for the aggregate
-- Is called for each item in an aggregation -- Is called for each item in an aggregation
create function int_agg_state (int4, int4) CREATE OR REPLACE FUNCTION int_agg_state (int4, int4)
returns int4 RETURNS int4
as 'MODULE_PATHNAME','int_agg_state' AS 'MODULE_PATHNAME','int_agg_state'
language 'c'; LANGUAGE 'C';
-- Internal function for the aggregate -- Internal function for the aggregate
-- Is called at the end of the aggregation, and returns an array. -- Is called at the end of the aggregation, and returns an array.
create function int_agg_final_array (int4) CREATE OR REPLACE FUNCTION int_agg_final_array (int4)
returns int4[] RETURNS int4[]
as 'MODULE_PATHNAME','int_agg_final_array' AS 'MODULE_PATHNAME','int_agg_final_array'
language 'c'; LANGUAGE 'C';
-- The aggration funcion. -- The aggration funcion.
-- uses the above functions to create an array of integers from an aggregation. -- uses the above functions to create an array of integers from an aggregation.
create aggregate int_array_aggregate CREATE OR REPLACE AGGREGATE int_array_aggregate (
(
BASETYPE = int4, BASETYPE = int4,
SFUNC = int_agg_state, SFUNC = int_agg_state,
STYPE = int4, STYPE = int4,
...@@ -33,8 +30,7 @@ create aggregate int_array_aggregate ...@@ -33,8 +30,7 @@ create aggregate int_array_aggregate
-- The enumeration function -- The enumeration function
-- returns each element in a one dimentional integer array -- returns each element in a one dimentional integer array
-- as a row. -- as a row.
create function int_array_enum(int4[]) CREATE OR REPLACE FUNCTION int_array_enum(int4[])
returns setof integer RETURNS setof integer
as 'MODULE_PATHNAME','int_enum' AS 'MODULE_PATHNAME','int_enum'
language 'c'; LANGUAGE 'C';
This diff is collapsed.
...@@ -3,364 +3,364 @@ ...@@ -3,364 +3,364 @@
-- does not depend on contents of seg.sql. -- does not depend on contents of seg.sql.
-- --
\set ECHO none \set ECHO none
psql:_int.sql:13: WARNING: ProcedureCreate: type query_int is not yet defined psql:_int.sql:15: WARNING: ProcedureCreate: type query_int is not yet defined
psql:_int.sql:18: WARNING: Argument type "query_int" is only a shell psql:_int.sql:20: WARNING: Argument type "query_int" is only a shell
select intset(1234); SELECT intset(1234);
intset intset
-------- --------
{1234} {1234}
(1 row) (1 row)
select icount('{1234234,234234}'); SELECT icount('{1234234,234234}');
icount icount
-------- --------
2 2
(1 row) (1 row)
select sort('{1234234,-30,234234}'); SELECT sort('{1234234,-30,234234}');
sort sort
---------------------- ----------------------
{-30,234234,1234234} {-30,234234,1234234}
(1 row) (1 row)
select sort('{1234234,-30,234234}','asc'); SELECT sort('{1234234,-30,234234}','asc');
sort sort
---------------------- ----------------------
{-30,234234,1234234} {-30,234234,1234234}
(1 row) (1 row)
select sort('{1234234,-30,234234}','desc'); SELECT sort('{1234234,-30,234234}','desc');
sort sort
---------------------- ----------------------
{1234234,234234,-30} {1234234,234234,-30}
(1 row) (1 row)
select sort_asc('{1234234,-30,234234}'); SELECT sort_asc('{1234234,-30,234234}');
sort_asc sort_asc
---------------------- ----------------------
{-30,234234,1234234} {-30,234234,1234234}
(1 row) (1 row)
select sort_desc('{1234234,-30,234234}'); SELECT sort_desc('{1234234,-30,234234}');
sort_desc sort_desc
---------------------- ----------------------
{1234234,234234,-30} {1234234,234234,-30}
(1 row) (1 row)
select uniq('{1234234,-30,-30,234234,-30}'); SELECT uniq('{1234234,-30,-30,234234,-30}');
uniq uniq
-------------------------- --------------------------
{1234234,-30,234234,-30} {1234234,-30,234234,-30}
(1 row) (1 row)
select uniq(sort_asc('{1234234,-30,-30,234234,-30}')); SELECT uniq(sort_asc('{1234234,-30,-30,234234,-30}'));
uniq uniq
---------------------- ----------------------
{-30,234234,1234234} {-30,234234,1234234}
(1 row) (1 row)
select idx('{1234234,-30,-30,234234,-30}',-30); SELECT idx('{1234234,-30,-30,234234,-30}',-30);
idx idx
----- -----
2 2
(1 row) (1 row)
select subarray('{1234234,-30,-30,234234,-30}',2,3); SELECT subarray('{1234234,-30,-30,234234,-30}',2,3);
subarray subarray
------------------ ------------------
{-30,-30,234234} {-30,-30,234234}
(1 row) (1 row)
select subarray('{1234234,-30,-30,234234,-30}',-1,1); SELECT subarray('{1234234,-30,-30,234234,-30}',-1,1);
subarray subarray
---------- ----------
{-30} {-30}
(1 row) (1 row)
select subarray('{1234234,-30,-30,234234,-30}',0,-1); SELECT subarray('{1234234,-30,-30,234234,-30}',0,-1);
subarray subarray
-------------------------- --------------------------
{1234234,-30,-30,234234} {1234234,-30,-30,234234}
(1 row) (1 row)
select #'{1234234,234234}'::int[]; SELECT #'{1234234,234234}'::int[];
?column? ?column?
---------- ----------
2 2
(1 row) (1 row)
select '{123,623,445}'::int[] + 1245; SELECT '{123,623,445}'::int[] + 1245;
?column? ?column?
-------------------- --------------------
{123,623,445,1245} {123,623,445,1245}
(1 row) (1 row)
select '{123,623,445}'::int[] + 445; SELECT '{123,623,445}'::int[] + 445;
?column? ?column?
------------------- -------------------
{123,623,445,445} {123,623,445,445}
(1 row) (1 row)
select '{123,623,445}'::int[] + '{1245,87,445}'; SELECT '{123,623,445}'::int[] + '{1245,87,445}';
?column? ?column?
--------------------------- ---------------------------
{123,623,445,1245,87,445} {123,623,445,1245,87,445}
(1 row) (1 row)
select '{123,623,445}'::int[] - 623; SELECT '{123,623,445}'::int[] - 623;
?column? ?column?
----------- -----------
{123,445} {123,445}
(1 row) (1 row)
select '{123,623,445}'::int[] - '{1623,623}'; SELECT '{123,623,445}'::int[] - '{1623,623}';
?column? ?column?
----------- -----------
{123,445} {123,445}
(1 row) (1 row)
select '{123,623,445}'::int[] | 623; SELECT '{123,623,445}'::int[] | 623;
?column? ?column?
--------------- ---------------
{123,445,623} {123,445,623}
(1 row) (1 row)
select '{123,623,445}'::int[] | 1623; SELECT '{123,623,445}'::int[] | 1623;
?column? ?column?
-------------------- --------------------
{123,445,623,1623} {123,445,623,1623}
(1 row) (1 row)
select '{123,623,445}'::int[] | '{1623,623}'; SELECT '{123,623,445}'::int[] | '{1623,623}';
?column? ?column?
-------------------- --------------------
{123,445,623,1623} {123,445,623,1623}
(1 row) (1 row)
select '{123,623,445}'::int[] & '{1623,623}'; SELECT '{123,623,445}'::int[] & '{1623,623}';
?column? ?column?
---------- ----------
{623} {623}
(1 row) (1 row)
--test query_int --test query_int
select '1'::query_int; SELECT '1'::query_int;
query_int query_int
----------- -----------
1 1
(1 row) (1 row)
select ' 1'::query_int; SELECT ' 1'::query_int;
query_int query_int
----------- -----------
1 1
(1 row) (1 row)
select '1 '::query_int; SELECT '1 '::query_int;
query_int query_int
----------- -----------
1 1
(1 row) (1 row)
select ' 1 '::query_int; SELECT ' 1 '::query_int;
query_int query_int
----------- -----------
1 1
(1 row) (1 row)
select ' ! 1 '::query_int; SELECT ' ! 1 '::query_int;
query_int query_int
----------- -----------
!1 !1
(1 row) (1 row)
select '!1'::query_int; SELECT '!1'::query_int;
query_int query_int
----------- -----------
!1 !1
(1 row) (1 row)
select '1|2'::query_int; SELECT '1|2'::query_int;
query_int query_int
----------- -----------
1 | 2 1 | 2
(1 row) (1 row)
select '1|!2'::query_int; SELECT '1|!2'::query_int;
query_int query_int
----------- -----------
1 | !2 1 | !2
(1 row) (1 row)
select '!1|2'::query_int; SELECT '!1|2'::query_int;
query_int query_int
----------- -----------
!1 | 2 !1 | 2
(1 row) (1 row)
select '!1|!2'::query_int; SELECT '!1|!2'::query_int;
query_int query_int
----------- -----------
!1 | !2 !1 | !2
(1 row) (1 row)
select '!(!1|!2)'::query_int; SELECT '!(!1|!2)'::query_int;
query_int query_int
-------------- --------------
!( !1 | !2 ) !( !1 | !2 )
(1 row) (1 row)
select '!(!1|2)'::query_int; SELECT '!(!1|2)'::query_int;
query_int query_int
------------- -------------
!( !1 | 2 ) !( !1 | 2 )
(1 row) (1 row)
select '!(1|!2)'::query_int; SELECT '!(1|!2)'::query_int;
query_int query_int
------------- -------------
!( 1 | !2 ) !( 1 | !2 )
(1 row) (1 row)
select '!(1|2)'::query_int; SELECT '!(1|2)'::query_int;
query_int query_int
------------ ------------
!( 1 | 2 ) !( 1 | 2 )
(1 row) (1 row)
select '1&2'::query_int; SELECT '1&2'::query_int;
query_int query_int
----------- -----------
1 & 2 1 & 2
(1 row) (1 row)
select '!1&2'::query_int; SELECT '!1&2'::query_int;
query_int query_int
----------- -----------
!1 & 2 !1 & 2
(1 row) (1 row)
select '1&!2'::query_int; SELECT '1&!2'::query_int;
query_int query_int
----------- -----------
1 & !2 1 & !2
(1 row) (1 row)
select '!1&!2'::query_int; SELECT '!1&!2'::query_int;
query_int query_int
----------- -----------
!1 & !2 !1 & !2
(1 row) (1 row)
select '(1&2)'::query_int; SELECT '(1&2)'::query_int;
query_int query_int
----------- -----------
1 & 2 1 & 2
(1 row) (1 row)
select '1&(2)'::query_int; SELECT '1&(2)'::query_int;
query_int query_int
----------- -----------
1 & 2 1 & 2
(1 row) (1 row)
select '!(1)&2'::query_int; SELECT '!(1)&2'::query_int;
query_int query_int
----------- -----------
!1 & 2 !1 & 2
(1 row) (1 row)
select '!(1&2)'::query_int; SELECT '!(1&2)'::query_int;
query_int query_int
------------ ------------
!( 1 & 2 ) !( 1 & 2 )
(1 row) (1 row)
select '1|2&3'::query_int; SELECT '1|2&3'::query_int;
query_int query_int
----------- -----------
1 | 2 & 3 1 | 2 & 3
(1 row) (1 row)
select '1|(2&3)'::query_int; SELECT '1|(2&3)'::query_int;
query_int query_int
----------- -----------
1 | 2 & 3 1 | 2 & 3
(1 row) (1 row)
select '(1|2)&3'::query_int; SELECT '(1|2)&3'::query_int;
query_int query_int
--------------- ---------------
( 1 | 2 ) & 3 ( 1 | 2 ) & 3
(1 row) (1 row)
select '1|2&!3'::query_int; SELECT '1|2&!3'::query_int;
query_int query_int
------------ ------------
1 | 2 & !3 1 | 2 & !3
(1 row) (1 row)
select '1|!2&3'::query_int; SELECT '1|!2&3'::query_int;
query_int query_int
------------ ------------
1 | !2 & 3 1 | !2 & 3
(1 row) (1 row)
select '!1|2&3'::query_int; SELECT '!1|2&3'::query_int;
query_int query_int
------------ ------------
!1 | 2 & 3 !1 | 2 & 3
(1 row) (1 row)
select '!1|(2&3)'::query_int; SELECT '!1|(2&3)'::query_int;
query_int query_int
------------ ------------
!1 | 2 & 3 !1 | 2 & 3
(1 row) (1 row)
select '!(1|2)&3'::query_int; SELECT '!(1|2)&3'::query_int;
query_int query_int
---------------- ----------------
!( 1 | 2 ) & 3 !( 1 | 2 ) & 3
(1 row) (1 row)
select '(!1|2)&3'::query_int; SELECT '(!1|2)&3'::query_int;
query_int query_int
---------------- ----------------
( !1 | 2 ) & 3 ( !1 | 2 ) & 3
(1 row) (1 row)
select '1|(2|(4|(5|6)))'::query_int; SELECT '1|(2|(4|(5|6)))'::query_int;
query_int query_int
------------------------------- -------------------------------
1 | ( 2 | ( 4 | ( 5 | 6 ) ) ) 1 | ( 2 | ( 4 | ( 5 | 6 ) ) )
(1 row) (1 row)
select '1|2|4|5|6'::query_int; SELECT '1|2|4|5|6'::query_int;
query_int query_int
------------------------------- -------------------------------
( ( ( 1 | 2 ) | 4 ) | 5 ) | 6 ( ( ( 1 | 2 ) | 4 ) | 5 ) | 6
(1 row) (1 row)
select '1&(2&(4&(5&6)))'::query_int; SELECT '1&(2&(4&(5&6)))'::query_int;
query_int query_int
------------------- -------------------
1 & 2 & 4 & 5 & 6 1 & 2 & 4 & 5 & 6
(1 row) (1 row)
select '1&2&4&5&6'::query_int; SELECT '1&2&4&5&6'::query_int;
query_int query_int
------------------- -------------------
1 & 2 & 4 & 5 & 6 1 & 2 & 4 & 5 & 6
(1 row) (1 row)
select '1&(2&(4&(5|6)))'::query_int; SELECT '1&(2&(4&(5|6)))'::query_int;
query_int query_int
----------------------- -----------------------
1 & 2 & 4 & ( 5 | 6 ) 1 & 2 & 4 & ( 5 | 6 )
(1 row) (1 row)
select '1&(2&(4&(5|!6)))'::query_int; SELECT '1&(2&(4&(5|!6)))'::query_int;
query_int query_int
------------------------ ------------------------
1 & 2 & 4 & ( 5 | !6 ) 1 & 2 & 4 & ( 5 | !6 )
...@@ -465,7 +465,7 @@ SELECT count(*) from test__int WHERE a @@ '(20&23)|(50&68)'; ...@@ -465,7 +465,7 @@ SELECT count(*) from test__int WHERE a @@ '(20&23)|(50&68)';
21 21
(1 row) (1 row)
drop index text_idx; DROP INDEX text_idx;
CREATE INDEX text_idx on test__int using gist ( a gist__intbig_ops ); CREATE INDEX text_idx on test__int using gist ( a gist__intbig_ops );
SELECT count(*) from test__int WHERE a && '{23,50}'; SELECT count(*) from test__int WHERE a && '{23,50}';
count count
......
...@@ -3,73 +3,74 @@ ...@@ -3,73 +3,74 @@
-- does not depend on contents of seg.sql. -- does not depend on contents of seg.sql.
-- --
\set ECHO none \set ECHO none
SET autocommit TO 'on';
\i _int.sql \i _int.sql
\set ECHO all \set ECHO all
select intset(1234); SELECT intset(1234);
select icount('{1234234,234234}'); SELECT icount('{1234234,234234}');
select sort('{1234234,-30,234234}'); SELECT sort('{1234234,-30,234234}');
select sort('{1234234,-30,234234}','asc'); SELECT sort('{1234234,-30,234234}','asc');
select sort('{1234234,-30,234234}','desc'); SELECT sort('{1234234,-30,234234}','desc');
select sort_asc('{1234234,-30,234234}'); SELECT sort_asc('{1234234,-30,234234}');
select sort_desc('{1234234,-30,234234}'); SELECT sort_desc('{1234234,-30,234234}');
select uniq('{1234234,-30,-30,234234,-30}'); SELECT uniq('{1234234,-30,-30,234234,-30}');
select uniq(sort_asc('{1234234,-30,-30,234234,-30}')); SELECT uniq(sort_asc('{1234234,-30,-30,234234,-30}'));
select idx('{1234234,-30,-30,234234,-30}',-30); SELECT idx('{1234234,-30,-30,234234,-30}',-30);
select subarray('{1234234,-30,-30,234234,-30}',2,3); SELECT subarray('{1234234,-30,-30,234234,-30}',2,3);
select subarray('{1234234,-30,-30,234234,-30}',-1,1); SELECT subarray('{1234234,-30,-30,234234,-30}',-1,1);
select subarray('{1234234,-30,-30,234234,-30}',0,-1); SELECT subarray('{1234234,-30,-30,234234,-30}',0,-1);
select #'{1234234,234234}'::int[]; SELECT #'{1234234,234234}'::int[];
select '{123,623,445}'::int[] + 1245; SELECT '{123,623,445}'::int[] + 1245;
select '{123,623,445}'::int[] + 445; SELECT '{123,623,445}'::int[] + 445;
select '{123,623,445}'::int[] + '{1245,87,445}'; SELECT '{123,623,445}'::int[] + '{1245,87,445}';
select '{123,623,445}'::int[] - 623; SELECT '{123,623,445}'::int[] - 623;
select '{123,623,445}'::int[] - '{1623,623}'; SELECT '{123,623,445}'::int[] - '{1623,623}';
select '{123,623,445}'::int[] | 623; SELECT '{123,623,445}'::int[] | 623;
select '{123,623,445}'::int[] | 1623; SELECT '{123,623,445}'::int[] | 1623;
select '{123,623,445}'::int[] | '{1623,623}'; SELECT '{123,623,445}'::int[] | '{1623,623}';
select '{123,623,445}'::int[] & '{1623,623}'; SELECT '{123,623,445}'::int[] & '{1623,623}';
--test query_int --test query_int
select '1'::query_int; SELECT '1'::query_int;
select ' 1'::query_int; SELECT ' 1'::query_int;
select '1 '::query_int; SELECT '1 '::query_int;
select ' 1 '::query_int; SELECT ' 1 '::query_int;
select ' ! 1 '::query_int; SELECT ' ! 1 '::query_int;
select '!1'::query_int; SELECT '!1'::query_int;
select '1|2'::query_int; SELECT '1|2'::query_int;
select '1|!2'::query_int; SELECT '1|!2'::query_int;
select '!1|2'::query_int; SELECT '!1|2'::query_int;
select '!1|!2'::query_int; SELECT '!1|!2'::query_int;
select '!(!1|!2)'::query_int; SELECT '!(!1|!2)'::query_int;
select '!(!1|2)'::query_int; SELECT '!(!1|2)'::query_int;
select '!(1|!2)'::query_int; SELECT '!(1|!2)'::query_int;
select '!(1|2)'::query_int; SELECT '!(1|2)'::query_int;
select '1&2'::query_int; SELECT '1&2'::query_int;
select '!1&2'::query_int; SELECT '!1&2'::query_int;
select '1&!2'::query_int; SELECT '1&!2'::query_int;
select '!1&!2'::query_int; SELECT '!1&!2'::query_int;
select '(1&2)'::query_int; SELECT '(1&2)'::query_int;
select '1&(2)'::query_int; SELECT '1&(2)'::query_int;
select '!(1)&2'::query_int; SELECT '!(1)&2'::query_int;
select '!(1&2)'::query_int; SELECT '!(1&2)'::query_int;
select '1|2&3'::query_int; SELECT '1|2&3'::query_int;
select '1|(2&3)'::query_int; SELECT '1|(2&3)'::query_int;
select '(1|2)&3'::query_int; SELECT '(1|2)&3'::query_int;
select '1|2&!3'::query_int; SELECT '1|2&!3'::query_int;
select '1|!2&3'::query_int; SELECT '1|!2&3'::query_int;
select '!1|2&3'::query_int; SELECT '!1|2&3'::query_int;
select '!1|(2&3)'::query_int; SELECT '!1|(2&3)'::query_int;
select '!(1|2)&3'::query_int; SELECT '!(1|2)&3'::query_int;
select '(!1|2)&3'::query_int; SELECT '(!1|2)&3'::query_int;
select '1|(2|(4|(5|6)))'::query_int; SELECT '1|(2|(4|(5|6)))'::query_int;
select '1|2|4|5|6'::query_int; SELECT '1|2|4|5|6'::query_int;
select '1&(2&(4&(5&6)))'::query_int; SELECT '1&(2&(4&(5&6)))'::query_int;
select '1&2&4&5&6'::query_int; SELECT '1&2&4&5&6'::query_int;
select '1&(2&(4&(5|6)))'::query_int; SELECT '1&(2&(4&(5|6)))'::query_int;
select '1&(2&(4&(5|!6)))'::query_int; SELECT '1&(2&(4&(5|!6)))'::query_int;
CREATE TABLE test__int( a int[] ); CREATE TABLE test__int( a int[] );
...@@ -96,7 +97,7 @@ SELECT count(*) from test__int WHERE a @@ '50&68'; ...@@ -96,7 +97,7 @@ SELECT count(*) from test__int WHERE a @@ '50&68';
SELECT count(*) from test__int WHERE a @ '{20,23}' or a @ '{50,68}'; SELECT count(*) from test__int WHERE a @ '{20,23}' or a @ '{50,68}';
SELECT count(*) from test__int WHERE a @@ '(20&23)|(50&68)'; SELECT count(*) from test__int WHERE a @@ '(20&23)|(50&68)';
drop index text_idx; DROP INDEX text_idx;
CREATE INDEX text_idx on test__int using gist ( a gist__intbig_ops ); CREATE INDEX text_idx on test__int using gist ( a gist__intbig_ops );
SELECT count(*) from test__int WHERE a && '{23,50}'; SELECT count(*) from test__int WHERE a && '{23,50}';
...@@ -107,4 +108,3 @@ SELECT count(*) from test__int WHERE a @ '{20,23}'; ...@@ -107,4 +108,3 @@ SELECT count(*) from test__int WHERE a @ '{20,23}';
SELECT count(*) from test__int WHERE a @@ '50&68'; SELECT count(*) from test__int WHERE a @@ '50&68';
SELECT count(*) from test__int WHERE a @ '{20,23}' or a @ '{50,68}'; SELECT count(*) from test__int WHERE a @ '{20,23}' or a @ '{50,68}';
SELECT count(*) from test__int WHERE a @@ '(20&23)|(50&68)'; SELECT count(*) from test__int WHERE a @@ '(20&23)|(50&68)';
-- --
-- PostgreSQL code for ISSNs. -- PostgreSQL code for ISSNs.
-- --
-- $Id: isbn_issn.sql.in,v 1.6 2002/08/22 00:01:39 tgl Exp $ -- $Id: isbn_issn.sql.in,v 1.7 2002/10/18 18:41:20 momjian Exp $
-- --
-- Adjust this setting to control where the objects get created. -- Adjust this setting to control where the objects get created.
SET search_path = public; SET search_path = public;
SET autocommit TO 'on';
-- --
-- Input and output functions and the type itself: -- Input and output functions and the type itself:
-- --
create function issn_in(cstring) CREATE FUNCTION issn_in(cstring)
returns issn RETURNS issn
as 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
language 'c'; LANGUAGE 'C';
create function issn_out(issn) CREATE FUNCTION issn_out(issn)
returns cstring RETURNS cstring
as 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
language 'c'; LANGUAGE 'C';
create type issn ( CREATE TYPE issn (
internallength = 16, INTERNALLENGTH = 16,
externallength = 9, EXTERNALLENGTH = 9,
input = issn_in, INPUT = issn_in,
output = issn_out OUTPUT = issn_out
); );
comment on type issn COMMENT ON TYPE issn
is 'International Standard Serial Number'; is 'International Standard Serial Number';
...@@ -37,35 +38,35 @@ comment on type issn ...@@ -37,35 +38,35 @@ comment on type issn
-- The various boolean tests: -- The various boolean tests:
-- --
create function issn_lt(issn, issn) CREATE FUNCTION issn_lt(issn, issn)
returns bool RETURNS bool
as 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
language 'c'; LANGUAGE 'C';
create function issn_le(issn, issn) CREATE FUNCTION issn_le(issn, issn)
returns bool RETURNS bool
as 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
language 'c'; LANGUAGE 'C';
create function issn_eq(issn, issn) CREATE FUNCTION issn_eq(issn, issn)
returns bool RETURNS bool
as 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
language 'c'; LANGUAGE 'C';
create function issn_ge(issn, issn) CREATE FUNCTION issn_ge(issn, issn)
returns bool RETURNS bool
as 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
language 'c'; LANGUAGE 'C';
create function issn_gt(issn, issn) CREATE FUNCTION issn_gt(issn, issn)
returns bool RETURNS bool
as 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
language 'c'; LANGUAGE 'C';
create function issn_ne(issn, issn) CREATE FUNCTION issn_ne(issn, issn)
returns bool RETURNS bool
as 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
language 'c'; LANGUAGE 'C';
-- --
-- Now the operators. Note how some of the parameters to some -- Now the operators. Note how some of the parameters to some
...@@ -74,47 +75,47 @@ create function issn_ne(issn, issn) ...@@ -74,47 +75,47 @@ create function issn_ne(issn, issn)
-- will be implicitly defined when those are, further down. -- will be implicitly defined when those are, further down.
-- --
create operator < ( CREATE OPERATOR < (
leftarg = issn, LEFTARG = issn,
rightarg = issn, RIGHTARG = issn,
-- negator = >=, -- NEGATOR = >=,
procedure = issn_lt PROCEDURE = issn_lt
); );
create operator <= ( CREATE OPERATOR <= (
leftarg = issn, LEFTARG = issn,
rightarg = issn, RIGHTARG = issn,
-- negator = >, -- NEGATOR = >,
procedure = issn_le PROCEDURE = issn_le
); );
create operator = ( CREATE OPERATOR = (
leftarg = issn, LEFTARG = issn,
rightarg = issn, RIGHTARG = issn,
commutator = =, COMMUTATOR = =,
-- negator = <>, -- NEGATOR = <>,
procedure = issn_eq PROCEDURE = issn_eq
); );
create operator >= ( CREATE OPERATOR >= (
leftarg = issn, LEFTARG = issn,
rightarg = issn, RIGHTARG = issn,
negator = <, NEGATOR = <,
procedure = issn_ge PROCEDURE = issn_ge
); );
create operator > ( CREATE OPERATOR > (
leftarg = issn, LEFTARG = issn,
rightarg = issn, RIGHTARG = issn,
negator = <=, NEGATOR = <=,
procedure = issn_gt PROCEDURE = issn_gt
); );
create operator <> ( CREATE OPERATOR <> (
leftarg = issn, LEFTARG = issn,
rightarg = issn, RIGHTARG = issn,
negator = =, NEGATOR = =,
procedure = issn_ne PROCEDURE = issn_ne
); );
-- --
...@@ -123,66 +124,65 @@ create operator <> ( ...@@ -123,66 +124,65 @@ create operator <> (
-- --
-- PostgreSQL code for ISBNs. -- PostgreSQL code for ISBNs.
-- --
-- $Id: isbn_issn.sql.in,v 1.6 2002/08/22 00:01:39 tgl Exp $ -- $Id: isbn_issn.sql.in,v 1.7 2002/10/18 18:41:20 momjian Exp $
-- --
-- --
-- Input and output functions and the type itself: -- Input and output functions and the type itself:
-- --
create function isbn_in(cstring) CREATE FUNCTION isbn_in(cstring)
returns isbn RETURNS isbn
as 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
language 'c'; LANGUAGE 'C';
create function isbn_out(isbn) CREATE FUNCTION isbn_out(isbn)
returns cstring RETURNS cstring
as 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
language 'c'; LANGUAGE 'C';
create type isbn ( CREATE TYPE isbn (
internallength = 16, INTERNALLENGTH = 16,
externallength = 13, EXTERNALLENGTH = 13,
input = isbn_in, INPUT = isbn_in,
output = isbn_out OUTPUT = isbn_out
); );
comment on type isbn COMMENT ON TYPE isbn IS 'International Standard Book Number';
is 'International Standard Book Number';
-- --
-- The various boolean tests: -- The various boolean tests:
-- --
create function isbn_lt(isbn, isbn) CREATE FUNCTION isbn_lt(isbn, isbn)
returns bool RETURNS bool
as 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
language 'c'; LANGUAGE 'C';
create function isbn_le(isbn, isbn) CREATE FUNCTION isbn_le(isbn, isbn)
returns bool RETURNS bool
as 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
language 'c'; LANGUAGE 'C';
create function isbn_eq(isbn, isbn) CREATE FUNCTION isbn_eq(isbn, isbn)
returns bool RETURNS bool
as 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
language 'c'; LANGUAGE 'C';
create function isbn_ge(isbn, isbn) CREATE FUNCTION isbn_ge(isbn, isbn)
returns bool RETURNS bool
as 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
language 'c'; LANGUAGE 'C';
create function isbn_gt(isbn, isbn) CREATE FUNCTION isbn_gt(isbn, isbn)
returns bool RETURNS bool
as 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
language 'c'; LANGUAGE 'C';
create function isbn_ne(isbn, isbn) CREATE FUNCTION isbn_ne(isbn, isbn)
returns bool RETURNS bool
as 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
language 'c'; LANGUAGE 'C';
-- --
-- Now the operators. Note how some of the parameters to some -- Now the operators. Note how some of the parameters to some
...@@ -191,61 +191,61 @@ create function isbn_ne(isbn, isbn) ...@@ -191,61 +191,61 @@ create function isbn_ne(isbn, isbn)
-- will be implicitly defined when those are, further down. -- will be implicitly defined when those are, further down.
-- --
create operator < ( CREATE OPERATOR < (
leftarg = isbn, LEFTARG = isbn,
rightarg = isbn, RIGHTARG = isbn,
-- negator = >=, -- NEGATOR = >=,
procedure = isbn_lt PROCEDURE = isbn_lt
); );
create operator <= ( CREATE OPERATOR <= (
leftarg = isbn, LEFTARG = isbn,
rightarg = isbn, RIGHTARG = isbn,
-- negator = >, -- NEGATOR = >,
procedure = isbn_le PROCEDURE = isbn_le
); );
create operator = ( CREATE OPERATOR = (
leftarg = isbn, LEFTARG = isbn,
rightarg = isbn, RIGHTARG = isbn,
commutator = =, COMMUTATOR = =,
-- negator = <>, -- NEGATOR = <>,
procedure = isbn_eq PROCEDURE = isbn_eq
); );
create operator >= ( CREATE OPERATOR >= (
leftarg = isbn, LEFTARG = isbn,
rightarg = isbn, RIGHTARG = isbn,
negator = <, NEGATOR = <,
procedure = isbn_ge PROCEDURE = isbn_ge
); );
create operator > ( CREATE OPERATOR > (
leftarg = isbn, LEFTARG = isbn,
rightarg = isbn, RIGHTARG = isbn,
negator = <=, NEGATOR = <=,
procedure = isbn_gt PROCEDURE = isbn_gt
); );
create operator <> ( CREATE OPERATOR <> (
leftarg = isbn, LEFTARG = isbn,
rightarg = isbn, RIGHTARG = isbn,
negator = =, NEGATOR = =,
procedure = isbn_ne PROCEDURE = isbn_ne
); );
-- Register 'isbn' comparison function -- Register 'isbn' comparison function
create function isbn_cmp(isbn, isbn) CREATE FUNCTION isbn_cmp(isbn, isbn)
returns integer RETURNS integer
as '$libdir/isbn_issn' AS '$libdir/isbn_issn'
language c; LANGUAGE c;
-- Register 'issn' comparison function -- Register 'issn' comparison function
create function issn_cmp(issn, issn) CREATE FUNCTION issn_cmp(issn, issn)
returns integer RETURNS integer
as '$libdir/isbn_issn' AS '$libdir/isbn_issn'
language c; LANGUAGE c;
------------------------------------------------- -------------------------------------------------
-- Create default operator class for 'isbn' -- -- Create default operator class for 'isbn' --
...@@ -253,7 +253,8 @@ create function issn_cmp(issn, issn) ...@@ -253,7 +253,8 @@ create function issn_cmp(issn, issn)
------------------------------------------------- -------------------------------------------------
CREATE OPERATOR CLASS isbn_ops CREATE OPERATOR CLASS isbn_ops
DEFAULT FOR TYPE isbn USING btree AS DEFAULT FOR TYPE isbn USING btree
AS
OPERATOR 1 < , OPERATOR 1 < ,
OPERATOR 2 <= , OPERATOR 2 <= ,
OPERATOR 3 = , OPERATOR 3 = ,
...@@ -267,7 +268,8 @@ CREATE OPERATOR CLASS isbn_ops ...@@ -267,7 +268,8 @@ CREATE OPERATOR CLASS isbn_ops
------------------------------------------------- -------------------------------------------------
CREATE OPERATOR CLASS issn_ops CREATE OPERATOR CLASS issn_ops
DEFAULT FOR TYPE issn USING btree AS DEFAULT FOR TYPE issn USING btree
AS
OPERATOR 1 < , OPERATOR 1 < ,
OPERATOR 2 <= , OPERATOR 2 <= ,
OPERATOR 3 = , OPERATOR 3 = ,
......
-- --
-- PostgreSQL code for LargeObjects -- PostgreSQL code for LargeObjects
-- --
-- $Id: lo.sql.in,v 1.7 2002/08/22 00:01:39 tgl Exp $ -- $Id: lo.sql.in,v 1.8 2002/10/18 18:41:20 momjian Exp $
-- --
-- --
-- Create the data type -- Create the data type
-- --
-- used by the lo type, it takes an oid and returns an lo object -- used by the lo type, it takes an oid and returns an lo object
create function lo_in(cstring)
returns lo -- Adjust this setting to control where the objects get created.
as 'MODULE_PATHNAME' SET search_path = public;
language 'c';
SET autocommit TO 'on';
CREATE FUNCTION lo_in(cstring)
RETURNS lo
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
-- used by the lo type, it returns the oid of the object -- used by the lo type, it returns the oid of the object
create function lo_out(lo) CREATE FUNCTION lo_out(lo)
returns cstring RETURNS cstring
as 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
language 'c'; LANGUAGE 'C';
-- finally the type itself -- finally the type itself
create type lo ( CREATE TYPE lo (
internallength = 4, INTERNALLENGTH = 4,
externallength = variable, EXTERNALLENGTH = variable,
input = lo_in, INPUT = lo_in,
output = lo_out OUTPUT = lo_out
); );
-- this returns the oid associated with a lo object -- this returns the oid associated with a lo object
create function lo_oid(lo) CREATE FUNCTION lo_oid(lo)
returns oid RETURNS oid
as 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
language 'c'; LANGUAGE 'C';
-- same function, named to allow it to be used as a type coercion, eg: -- same function, named to allow it to be used as a type coercion, eg:
-- create table a (image lo); -- CREATE TABLE a (image lo);
-- select image::oid from a; -- SELECT image::oid FROM a;
-- --
create function oid(lo) CREATE FUNCTION oid(lo)
returns oid RETURNS oid
as 'MODULE_PATHNAME', 'lo_oid' AS 'MODULE_PATHNAME', 'lo_oid'
language 'c'; LANGUAGE 'C';
-- this allows us to convert an oid to a managed lo object -- this allows us to convert an oid to a managed lo object
-- ie: insert into test values (lo_import('/fullpath/file')::lo); -- ie: insert into test values (lo_import('/fullpath/file')::lo);
create function lo(oid) CREATE FUNCTION lo(oid)
returns lo RETURNS lo
as 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
language 'c'; LANGUAGE 'C';
-- This is used in triggers -- This is used in triggers
create function lo_manage() CREATE FUNCTION lo_manage()
returns trigger RETURNS trigger
as 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
language 'c'; LANGUAGE 'C';
...@@ -3,13 +3,18 @@ ...@@ -3,13 +3,18 @@
-- It's used just for development -- It's used just for development
-- --
-- Adjust this setting to control where the objects get created.
SET search_path = public;
SET autocommit TO 'on';
-- remove our test table -- remove our test table
drop table a; DROP TABLE a;
-- now drop the type and associated C functions -- now drop the type and associated C functions
drop type lo CASCADE; DROP TYPE lo CASCADE;
-- the trigger function has no dependency on the type, so drop separately -- the trigger function has no dependency on the type, so drop separately
drop function lo_manage(); DROP FUNCTION lo_manage();
-- the lo stuff is now removed from the system -- the lo stuff is now removed from the system
...@@ -5,53 +5,65 @@ ...@@ -5,53 +5,65 @@
-- --
-- ignore any errors here - simply drop the table if it already exists -- ignore any errors here - simply drop the table if it already exists
drop table a; DROP TABLE a;
-- create the test table -- create the test table
create table a (fname name,image lo); CREATE TABLE a (fname name,image lo);
-- insert a null object -- insert a null object
insert into a values ('null'); INSERT INTO a VALUES ('null');
-- insert an empty large object -- insert an empty large object
insert into a values ('empty',''); INSERT INTO a VALUES ('empty','');
-- insert a large object based on a file -- insert a large object based on a file
insert into a values ('/etc/group',lo_import('/etc/group')::lo); INSERT INTO a VALUES ('/etc/group',lo_import('/etc/group')::lo);
-- now select the table -- now select the table
select * from a; SELECT * FROM a;
-- this select also returns an oid based on the lo column -- this select also returns an oid based on the lo column
select *,image::oid from a; SELECT *,image::oid from a;
-- now test the trigger -- now test the trigger
create trigger t_a before update or delete on a for each row execute procedure lo_manage(image); CREATE TRIGGER t_a
BEFORE UPDATE OR DELETE ON a
FOR EACH ROW
EXECUTE PROCEDURE lo_manage(image);
-- insert -- insert
insert into a values ('aa',''); INSERT INTO a VALUES ('aa','');
select * from a where fname like 'aa%'; SELECT * FROM a
WHERE fname LIKE 'aa%';
-- update -- update
update a set image=lo_import('/etc/group')::lo where fname='aa'; UPDATE a SET image=lo_import('/etc/group')::lo
select * from a where fname like 'aa%'; WHERE fname='aa';
SELECT * FROM a
WHERE fname LIKE 'aa%';
-- update the 'empty' row which should be null -- update the 'empty' row which should be null
update a set image=lo_import('/etc/hosts')::lo where fname='empty'; UPDATE a SET image=lo_import('/etc/hosts')::lo
select * from a where fname like 'empty%'; WHERE fname='empty';
update a set image=null where fname='empty'; SELECT * FROM a
select * from a where fname like 'empty%'; WHERE fname LIKE 'empty%';
UPDATE a SET image=null
WHERE fname='empty';
SELECT * FROM a
WHERE fname LIKE 'empty%';
-- delete the entry -- delete the entry
delete from a where fname='aa'; DELETE FROM a
select * from a where fname like 'aa%'; WHERE fname='aa';
SELECT * FROM a
WHERE fname LIKE 'aa%';
-- This deletes the table contents. Note, if you comment this out, and -- This deletes the table contents. Note, if you comment this out, and
-- expect the drop table to remove the objects, think again. The trigger -- expect the drop table to remove the objects, think again. The trigger
-- doesn't get thrown by drop table. -- doesn't get thrown by drop table.
delete from a; DELETE FROM a;
-- finally drop the table -- finally drop the table
drop table a; DROP TABLE a;
-- end of tests -- end of tests
This diff is collapsed.
This diff is collapsed.
create table test ( path ltree); CREATE TABLE test ( path ltree);
insert into test values ('Top'); INSERT INTO test VALUES ('Top');
insert into test values ('Top.Science'); INSERT INTO test VALUES ('Top.Science');
insert into test values ('Top.Science.Astronomy'); INSERT INTO test VALUES ('Top.Science.Astronomy');
insert into test values ('Top.Science.Astronomy.Astrophysics'); INSERT INTO test VALUES ('Top.Science.Astronomy.Astrophysics');
insert into test values ('Top.Science.Astronomy.Cosmology'); INSERT INTO test VALUES ('Top.Science.Astronomy.Cosmology');
insert into test values ('Top.Hobbies'); INSERT INTO test VALUES ('Top.Hobbies');
insert into test values ('Top.Hobbies.Amateurs_Astronomy'); INSERT INTO test VALUES ('Top.Hobbies.Amateurs_Astronomy');
insert into test values ('Top.Collections'); INSERT INTO test VALUES ('Top.Collections');
insert into test values ('Top.Collections.Pictures'); INSERT INTO test VALUES ('Top.Collections.Pictures');
insert into test values ('Top.Collections.Pictures.Astronomy'); INSERT INTO test VALUES ('Top.Collections.Pictures.Astronomy');
insert into test values ('Top.Collections.Pictures.Astronomy.Stars'); INSERT INTO test VALUES ('Top.Collections.Pictures.Astronomy.Stars');
insert into test values ('Top.Collections.Pictures.Astronomy.Galaxies'); INSERT INTO test VALUES ('Top.Collections.Pictures.Astronomy.Galaxies');
insert into test values ('Top.Collections.Pictures.Astronomy.Astronauts'); INSERT INTO test VALUES ('Top.Collections.Pictures.Astronomy.Astronauts');
create index path_gist_idx on test using gist(path); CREATE INDEX path_gist_idx ON test USING gist(path);
create index path_idx on test using btree(path); CREATE INDEX path_idx ON test USING btree(path);
This diff is collapsed.
This diff is collapsed.
DROP FUNCTION noup (); -- Adjust this setting to control where the objects get created.
SET search_path = public;
CREATE FUNCTION noup () SET autocommit TO 'on';
RETURNS trigger
AS 'MODULE_PATHNAME' CREATE OR REPLACE FUNCTION noup ()
LANGUAGE 'C'; RETURNS trigger
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment