Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
cd7a3b6c
Commit
cd7a3b6c
authored
22 years ago
by
Tom Lane
Browse files
Options
Downloads
Patches
Plain Diff
Simplify handling of second database for dblink tests.
parent
b66ba36b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
contrib/dblink/expected/dblink.out
+23
-41
23 additions, 41 deletions
contrib/dblink/expected/dblink.out
contrib/dblink/sql/dblink.sql
+20
-38
20 additions, 38 deletions
contrib/dblink/sql/dblink.sql
with
43 additions
and
79 deletions
contrib/dblink/expected/dblink.out
+
23
−
41
View file @
cd7a3b6c
--
--
-- First, create a slave database and define the functions.
-- First, create a slave database and define the functions and test data
-- Turn off echoing so that expected file does not depend on
-- therein.
-- contents of dblink.sql.
--
-- This initial hackery is to allow successive runs without failures.
--
--
CREATE OR REPLACE FUNCTION conditional_drop() RETURNS text AS '
DECLARE
dbname text;
BEGIN
SELECT INTO dbname datname FROM pg_database WHERE datname = ''regression_slave'';
IF FOUND THEN
DROP DATABASE regression_slave;
END IF;
RETURN ''OK'';
END;
' LANGUAGE 'plpgsql';
SELECT conditional_drop();
conditional_drop
------------------
OK
(1 row)
CREATE DATABASE regression_slave;
CREATE DATABASE regression_slave;
\connect regression_slave
\connect regression_slave
-- Turn off echoing so that expected file does not depend on
-- 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'
...
@@ -219,41 +239,3 @@ select dblink_disconnect();
...
@@ -219,41 +239,3 @@ select dblink_disconnect();
OK
OK
(1 row)
(1 row)
-- now wait for the connection to the slave to be cleared before
-- we try to drop the database
CREATE FUNCTION wait() RETURNS TEXT AS '
DECLARE
rec record;
cntr int;
BEGIN
cntr = 0;
select into rec d.datname
from pg_database d,
(select pg_stat_get_backend_dbid(pg_stat_get_backend_idset()) AS dbid) b
where d.oid = b.dbid and d.datname = ''regression_slave'';
WHILE FOUND LOOP
cntr = cntr + 1;
select into rec d.datname
from pg_database d,
(select pg_stat_get_backend_dbid(pg_stat_get_backend_idset()) AS dbid) b
where d.oid = b.dbid and d.datname = ''regression_slave'';
-- safety valve
if cntr > 1000 THEN
EXIT;
end if;
END LOOP;
RETURN ''OK'';
END;
' LANGUAGE 'plpgsql';
SELECT wait();
wait
------
OK
(1 row)
-- OK, safe to drop the slave
DROP DATABASE regression_slave;
This diff is collapsed.
Click to expand it.
contrib/dblink/sql/dblink.sql
+
20
−
38
View file @
cd7a3b6c
--
--
-- First, create a slave database and define the functions.
-- First, create a slave database and define the functions and test data
-- Turn off echoing so that expected file does not depend on
-- therein.
-- contents of dblink.sql.
--
-- This initial hackery is to allow successive runs without failures.
--
--
CREATE
OR
REPLACE
FUNCTION
conditional_drop
()
RETURNS
text
AS
'
DECLARE
dbname text;
BEGIN
SELECT INTO dbname datname FROM pg_database WHERE datname =
''
regression_slave
''
;
IF FOUND THEN
DROP DATABASE regression_slave;
END IF;
RETURN
''
OK
''
;
END;
'
LANGUAGE
'plpgsql'
;
SELECT
conditional_drop
();
CREATE
DATABASE
regression_slave
;
CREATE
DATABASE
regression_slave
;
\
connect
regression_slave
\
connect
regression_slave
-- Turn off echoing so that expected file does not depend on
-- contents of dblink.sql.
\
set
ECHO
none
\
set
ECHO
none
\
i
dblink
.
sql
\
i
dblink
.
sql
\
set
ECHO
all
\
set
ECHO
all
...
@@ -112,38 +129,3 @@ select * from dblink('select * from foo') as t(a int, b text, c text[]) where a
...
@@ -112,38 +129,3 @@ select * from dblink('select * from foo') as t(a int, b text, c text[]) where a
-- close the persistent connection
-- close the persistent connection
select
dblink_disconnect
();
select
dblink_disconnect
();
-- now wait for the connection to the slave to be cleared before
-- we try to drop the database
CREATE
FUNCTION
wait
()
RETURNS
TEXT
AS
'
DECLARE
rec record;
cntr int;
BEGIN
cntr = 0;
select into rec d.datname
from pg_database d,
(select pg_stat_get_backend_dbid(pg_stat_get_backend_idset()) AS dbid) b
where d.oid = b.dbid and d.datname =
''
regression_slave
''
;
WHILE FOUND LOOP
cntr = cntr + 1;
select into rec d.datname
from pg_database d,
(select pg_stat_get_backend_dbid(pg_stat_get_backend_idset()) AS dbid) b
where d.oid = b.dbid and d.datname =
''
regression_slave
''
;
-- safety valve
if cntr > 1000 THEN
EXIT;
end if;
END LOOP;
RETURN
''
OK
''
;
END;
'
LANGUAGE
'plpgsql'
;
SELECT
wait
();
-- OK, safe to drop the slave
DROP
DATABASE
regression_slave
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment