Index: src/test/regress/expected/namespace.out
===================================================================
RCS file: /usr/local/cvsroot/pgsql-server/src/test/regress/expected/namespace.out,v
retrieving revision 1.2
diff -c -r1.2 namespace.out
*** src/test/regress/expected/namespace.out	10 Jun 2004 17:56:01 -0000	1.2
--- src/test/regress/expected/namespace.out	10 Sep 2004 04:44:25 -0000
***************
*** 1,10 ****
  --
! -- Regression tests for schemas (namespaces)
! --
  CREATE SCHEMA test_schema_1
         CREATE UNIQUE INDEX abc_a_idx ON abc (a)
         CREATE VIEW abc_view AS
                SELECT a+1 AS a, b+1 AS b FROM abc
         CREATE TABLE abc (
                a serial,
                b int UNIQUE
--- 1,216 ----
+ -- Validate the relationship between multiple schemas and the search path.
  --
! set search_path to public;
! SHOW search_path;--should show only public
!  search_path 
! -------------
!  public
! (1 row)
! 
! CREATE SCHEMA schm1
! 	CREATE TABLE testschmtbl ( id int primary key, a int unique);
! NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "testschmtbl_pkey" for table "testschmtbl"
! NOTICE:  CREATE TABLE / UNIQUE will create implicit index "testschmtbl_a_key" for table "testschmtbl"
! CREATE SCHEMA schm2
! 	CREATE TABLE testschmtbl ( id int primary key, a int unique);
! NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "testschmtbl_pkey" for table "testschmtbl"
! NOTICE:  CREATE TABLE / UNIQUE will create implicit index "testschmtbl_a_key" for table "testschmtbl"
! CREATE SCHEMA schm3;
! CREATE TABLE schm3.testschmtbl ( id int primary key, a int unique);
! NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "testschmtbl_pkey" for table "testschmtbl"
! NOTICE:  CREATE TABLE / UNIQUE will create implicit index "testschmtbl_a_key" for table "testschmtbl"
! SELECT current_schemas(true);--should show above three schemas
!    current_schemas   
! ---------------------
!  {pg_catalog,public}
! (1 row)
! 
! --This should be an error.
! --Because public.testschmtbl doesn't exist yet.
! INSERT INTO testschmtbl (id, a) VALUES ( 1,1);
! ERROR:  relation "testschmtbl" does not exist
! INSERT INTO schm1.testschmtbl (id, a) VALUES ( 1,1);--OK
! -- Create PUBLIC's testschmtbl
! CREATE TABLE testschmtbl ( id int primary key, a int unique);
! NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "testschmtbl_pkey" for table "testschmtbl"
! NOTICE:  CREATE TABLE / UNIQUE will create implicit index "testschmtbl_a_key" for table "testschmtbl"
! --Should not cause any error
! --Because this is PUBLIC's testschmtbl
! INSERT INTO testschmtbl (id, a) VALUES ( 1,1);
! --The following two queries below should be a duplicate error.
! INSERT INTO testschmtbl (id, a) VALUES ( 1,1);--PUBLIC's
! ERROR:  duplicate key violates unique constraint "testschmtbl_pkey"
! INSERT INTO schm1.testschmtbl (id, a) VALUES ( 1,1);--SCHM1's
! ERROR:  duplicate key violates unique constraint "testschmtbl_pkey"
! select * from public.testschmtbl;--1 row
!  id | a 
! ----+---
!   1 | 1
! (1 row)
! 
! select * from testschmtbl;--1 row. This is PUBLIC's.
!  id | a 
! ----+---
!   1 | 1
! (1 row)
! 
! select * from schm1.testschmtbl;--1 row
!  id | a 
! ----+---
!   1 | 1
! (1 row)
! 
! select * from schm2.testschmtbl;--0 row
!  id | a 
! ----+---
! (0 rows)
! 
! select * from schm3.testschmtbl;--0 row
!  id | a 
! ----+---
! (0 rows)
! 
! set search_path to schm1, public, schm2, schm3;
! SHOW search_path;
!          search_path         
! -----------------------------
!  schm1, public, schm2, schm3
! (1 row)
! 
! INSERT INTO testschmtbl (id, a) VALUES ( 2,2);
! INSERT INTO schm1.testschmtbl (id, a) VALUES ( 2,2);--duplicate error
! ERROR:  duplicate key violates unique constraint "testschmtbl_pkey"
! select * from public.testschmtbl;--1 row
!  id | a 
! ----+---
!   1 | 1
! (1 row)
! 
! select * from schm1.testschmtbl;--2 row
!  id | a 
! ----+---
!   1 | 1
!   2 | 2
! (2 rows)
! 
! select * from schm2.testschmtbl;--0 row
!  id | a 
! ----+---
! (0 rows)
! 
! select * from schm3.testschmtbl;--0 row
!  id | a 
! ----+---
! (0 rows)
! 
! INSERT INTO public.testschmtbl (id, a) VALUES ( 2,2);--should not be an error
! CREATE TABLE schm2.testschmtbl2( id int primary key, a int unique);
! NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "testschmtbl2_pkey" for table "testschmtbl2"
! NOTICE:  CREATE TABLE / UNIQUE will create implicit index "testschmtbl2_a_key" for table "testschmtbl2"
! CREATE TABLE schm3.testschmtbl2( id int primary key, a int unique);
! NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "testschmtbl2_pkey" for table "testschmtbl2"
! NOTICE:  CREATE TABLE / UNIQUE will create implicit index "testschmtbl2_a_key" for table "testschmtbl2"
! CREATE TABLE schm3.testschmtbl3( id int primary key, a int unique);
! NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "testschmtbl3_pkey" for table "testschmtbl3"
! NOTICE:  CREATE TABLE / UNIQUE will create implicit index "testschmtbl3_a_key" for table "testschmtbl3"
! set search_path to schm2, schm3, public, schm1;
! SHOW search_path;
!          search_path         
! -----------------------------
!  schm2, schm3, public, schm1
! (1 row)
! 
! --Should not cause any error
! --Insert values into schm2's testschmtbl
! INSERT INTO testschmtbl (id, a) VALUES ( 2,2);
! SET search_path TO schm1, public;
! --Should be an error.
! --Relation testchmtbl2 doesn't exist in the schm1 schema.
! INSERT INTO testchmtbl2 (id, a) VALUES (2,2);
! ERROR:  relation "testchmtbl2" does not exist
! SET search_path TO schm1, public, schm3, schm2;
! --Should not be an error
! --Insert values into schm3's testschmtbl2
! INSERT INTO testschmtbl2 (id, a) VALUES (2,2);
! select * from schm2.testschmtbl2;
!  id | a 
! ----+---
! (0 rows)
! 
! select * from schm3.testschmtbl2;
!  id | a 
! ----+---
!   2 | 2
! (1 row)
! 
! INSERT INTO testschmtbl3 (id, a) VALUES (2,2);--Should not be an error
! select * from schm3.testschmtbl3;
!  id | a 
! ----+---
!   2 | 2
! (1 row)
! 
! --DROP TABLE testschmtbl CASCADE;
! set search_path to schm1, public, schm2, schm3;
! BEGIN;
! TRUNCATE testschmtbl;--This should truncate the schm1's testschmtbl
! COMMIT;
! select * from public.testschmtbl;-- row
!  id | a 
! ----+---
!   1 | 1
!   2 | 2
! (2 rows)
! 
! select * from schm1.testschmtbl;--0 row
!  id | a 
! ----+---
! (0 rows)
! 
! select * from schm2.testschmtbl;-- row
!  id | a 
! ----+---
!   2 | 2
! (1 row)
! 
! select * from schm3.testschmtbl;-- row
!  id | a 
! ----+---
! (0 rows)
! 
! DROP TABLE public.testschmtbl CASCADE;
! DROP SCHEMA schm1 CASCADE;
! NOTICE:  drop cascades to table testschmtbl
! DROP SCHEMA schm2 CASCADE;
! NOTICE:  drop cascades to table testschmtbl2
! NOTICE:  drop cascades to table testschmtbl
! DROP SCHEMA schm3 CASCADE;
! NOTICE:  drop cascades to table testschmtbl3
! NOTICE:  drop cascades to table testschmtbl2
! NOTICE:  drop cascades to table testschmtbl
! select current_schemas(true);
!    current_schemas   
! ---------------------
!  {pg_catalog,public}
! (1 row)
! 
! SHOW search_path;
!          search_path         
! -----------------------------
!  schm1, public, schm2, schm3
! (1 row)
! 
! --Verify schema_elements
  CREATE SCHEMA test_schema_1
         CREATE UNIQUE INDEX abc_a_idx ON abc (a)
+        CREATE SEQUENCE abc_seq START WITH 1 INCREMENT BY 2
         CREATE VIEW abc_view AS
                SELECT a+1 AS a, b+1 AS b FROM abc
+        CREATE TRIGGER schmtrigger
+       BEFORE INSERT OR UPDATE ON abc
+        FOR EACH ROW
+        EXECUTE PROCEDURE
+        autoinc(b, abc_seq)
         CREATE TABLE abc (
                a serial,
                b int UNIQUE
***************
*** 16,52 ****
      (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_1');
   count 
  -------
!      5
  (1 row)
  
  INSERT INTO test_schema_1.abc DEFAULT VALUES;
  INSERT INTO test_schema_1.abc DEFAULT VALUES;
  INSERT INTO test_schema_1.abc DEFAULT VALUES;
  SELECT * FROM test_schema_1.abc;
   a | b 
  ---+---
!  1 |  
!  2 |  
!  3 |  
! (3 rows)
  
  SELECT * FROM test_schema_1.abc_view;
   a | b 
  ---+---
!  2 |  
!  3 |  
!  4 |  
! (3 rows)
  
  DROP SCHEMA test_schema_1 CASCADE;
! NOTICE:  drop cascades to view test_schema_1.abc_view
! NOTICE:  drop cascades to rule _RETURN on view test_schema_1.abc_view
! NOTICE:  drop cascades to table test_schema_1.abc
  -- verify that the objects were dropped
  SELECT COUNT(*) FROM pg_class WHERE relnamespace =
!     (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_1');
   count 
  -------
       0
  (1 row)
  
--- 222,373 ----
      (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_1');
   count 
  -------
!      6
  (1 row)
  
+ --The following query will fail because the schema test_schema_1 is not
+ -- on the search_path yet.
  INSERT INTO test_schema_1.abc DEFAULT VALUES;
+ ERROR:  relation "abc_seq" does not exist
+ SELECT nextval('test_schema_1.abc_seq');
+  nextval 
+ ---------
+        1
+ (1 row)
+ 
+ set search_path to test_schema_1, public;
  INSERT INTO test_schema_1.abc DEFAULT VALUES;
  INSERT INTO test_schema_1.abc DEFAULT VALUES;
  SELECT * FROM test_schema_1.abc;
   a | b 
  ---+---
!  2 | 3
!  3 | 5
! (2 rows)
  
  SELECT * FROM test_schema_1.abc_view;
   a | b 
  ---+---
!  3 | 4
!  4 | 6
! (2 rows)
! 
! SET search_path to test_schema_1, public;
! ALTER SCHEMA test_schema_1 RENAME TO test_schema_2;
! SELECT COUNT(*) FROM pg_class WHERE relnamespace =
!     (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_1');
!  count 
! -------
!      0
! (1 row)
! 
! SELECT COUNT(*) FROM pg_class WHERE relnamespace =
!     (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_2');
!  count 
! -------
!      6
! (1 row)
! 
! SELECT * FROM test_schema_2.abc;
!  a | b 
! ---+---
!  2 | 3
!  3 | 5
! (2 rows)
! 
! SELECT * FROM test_schema_2.abc_view;
!  a | b 
! ---+---
!  3 | 4
!  4 | 6
! (2 rows)
! 
! SHOW search_path;
!       search_path      
! -----------------------
!  test_schema_1, public
! (1 row)
  
  DROP SCHEMA test_schema_1 CASCADE;
! ERROR:  schema "test_schema_1" does not exist
! DROP SCHEMA test_schema_2 CASCADE;
! NOTICE:  drop cascades to view test_schema_2.abc_view
! NOTICE:  drop cascades to rule _RETURN on view test_schema_2.abc_view
! NOTICE:  drop cascades to table test_schema_2.abc
! NOTICE:  drop cascades to sequence test_schema_2.abc_seq
  -- verify that the objects were dropped
  SELECT COUNT(*) FROM pg_class WHERE relnamespace =
!     (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_2');
   count 
  -------
       0
  (1 row)
  
+ -- Verify priviledge
+ CREATE USER NSTESTER1;
+ CREATE USER NSTESTER2;
+ CREATE USER NSTESTER3;
+ CREATE SCHEMA AUTHORIZATION nstester1;
+ CREATE SCHEMA AUTHORIZATION nstester2;
+ CREATE SCHEMA schm3 AUTHORIZATION nstester3;
+ ALTER SCHEMA schm3 OWNER TO nstester2;
+ GRANT USAGE ON SCHEMA nstester1 TO nstester1;
+ SET SESSION AUTHORIZATION nstester1;
+ CREATE TABLE nstester2.testtbl ( a int unique);
+ ERROR:  permission denied for schema nstester2
+ SET SESSION AUTHORIZATION nstester2;
+ SELECT session_user, current_user;
+  session_user | current_user 
+ --------------+--------------
+  nstester2    | nstester2
+ (1 row)
+ 
+ GRANT ALL ON SCHEMA nstester2 TO nstester1;
+ SET SESSION AUTHORIZATION nstester1;
+ CREATE TABLE nstester2.testtbl ( a int unique);
+ NOTICE:  CREATE TABLE / UNIQUE will create implicit index "testtbl_a_key" for table "testtbl"
+ RESET SESSION AUTHORIZATION;
+ DROP USER nstester1;
+ DROP USER nstester2;
+ DROP USER nstester3;
+ DROP SCHEMA nstester1 CASCADE;
+ DROP SCHEMA nstester2 CASCADE;
+ NOTICE:  drop cascades to table nstester2.testtbl
+ DROP SCHEMA schm3 CASCADE;
+ set search_path to public;
+ --test build-in visibility-functions
+ CREATE SCHEMA testvisibleschm;
+ CREATE TABLE testvisibleschm.mytable ( a int);
+ CREATE TYPE testvisibleschm.mytype AS (a int, b int);
+ CREATE FUNCTION testvisibleschm.myfunc ( integer, integer ) RETURNS integer
+ AS $$select $1 + $2; $$ LANGUAGE SQL;
+ CREATE OPERATOR testvisibleschm.^=^ (
+ 	leftarg = int4, rightarg = int4,
+ 	procedure = testvisibleschm.myfunc
+ );
+ SELECT pg_table_is_visible('testvisibleschm.mytable'::regclass) as table,
+ pg_type_is_visible('testvisibleschm.mytype'::regtype) as type,
+ pg_function_is_visible('testvisibleschm.myfunc'::regproc) as func,
+ pg_operator_is_visible('testvisibleschm.^=^'::regoper) as opr;
+  table | type | func | opr 
+ -------+------+------+-----
+  f     | f    | f    | f
+ (1 row)
+ 
+ SET search_path to testvisibleschm;
+ SELECT pg_table_is_visible('testvisibleschm.mytable'::regclass) as table,
+ pg_type_is_visible('testvisibleschm.mytype'::regtype) as type,
+ pg_function_is_visible('myfunc'::regproc) as func,
+ pg_operator_is_visible('^=^'::regoper) as opr;
+  table | type | func | opr 
+ -------+------+------+-----
+  t     | t    | t    | t
+ (1 row)
+ 
+ DROP SCHEMA testvisibleschm CASCADE;
+ NOTICE:  drop cascades to operator ^=^(integer,integer)
+ NOTICE:  drop cascades to function myfunc(integer,integer)
+ NOTICE:  drop cascades to composite type mytype
+ NOTICE:  drop cascades to type mytype
+ NOTICE:  drop cascades to table mytable
+ set search_path to public;
Index: src/test/regress/sql/namespace.sql
===================================================================
RCS file: /usr/local/cvsroot/pgsql-server/src/test/regress/sql/namespace.sql,v
retrieving revision 1.1
diff -c -r1.1 namespace.sql
*** src/test/regress/sql/namespace.sql	11 Jan 2004 04:58:17 -0000	1.1
--- src/test/regress/sql/namespace.sql	10 Sep 2004 04:43:10 -0000
***************
*** 1,13 ****
  --
! -- Regression tests for schemas (namespaces)
! --
  
  CREATE SCHEMA test_schema_1
         CREATE UNIQUE INDEX abc_a_idx ON abc (a)
  
         CREATE VIEW abc_view AS
                SELECT a+1 AS a, b+1 AS b FROM abc
  
         CREATE TABLE abc (
                a serial,
                b int UNIQUE
--- 1,106 ----
+ -- Validate the relationship between multiple schemas and the search path.
  --
! set search_path to public;
! SHOW search_path;--should show only public
! CREATE SCHEMA schm1
! 	CREATE TABLE testschmtbl ( id int primary key, a int unique);
! CREATE SCHEMA schm2
! 	CREATE TABLE testschmtbl ( id int primary key, a int unique);
! CREATE SCHEMA schm3;
! CREATE TABLE schm3.testschmtbl ( id int primary key, a int unique);
! SELECT current_schemas(true);--should show above three schemas
! 
! --This should be an error.
! --Because public.testschmtbl doesn't exist yet.
! INSERT INTO testschmtbl (id, a) VALUES ( 1,1);
! 
! INSERT INTO schm1.testschmtbl (id, a) VALUES ( 1,1);--OK
! 
! -- Create PUBLIC's testschmtbl
! CREATE TABLE testschmtbl ( id int primary key, a int unique);
! --Should not cause any error
! --Because this is PUBLIC's testschmtbl
! INSERT INTO testschmtbl (id, a) VALUES ( 1,1);
! 
! --The following two queries below should be a duplicate error.
! INSERT INTO testschmtbl (id, a) VALUES ( 1,1);--PUBLIC's
! INSERT INTO schm1.testschmtbl (id, a) VALUES ( 1,1);--SCHM1's
! 
! select * from public.testschmtbl;--1 row
! select * from testschmtbl;--1 row. This is PUBLIC's.
! select * from schm1.testschmtbl;--1 row
! select * from schm2.testschmtbl;--0 row
! select * from schm3.testschmtbl;--0 row
! 
! set search_path to schm1, public, schm2, schm3;
! SHOW search_path;
! 
! INSERT INTO testschmtbl (id, a) VALUES ( 2,2);
! INSERT INTO schm1.testschmtbl (id, a) VALUES ( 2,2);--duplicate error
! select * from public.testschmtbl;--1 row
! select * from schm1.testschmtbl;--2 row
! select * from schm2.testschmtbl;--0 row
! select * from schm3.testschmtbl;--0 row
! 
! INSERT INTO public.testschmtbl (id, a) VALUES ( 2,2);--should not be an error
! 
! CREATE TABLE schm2.testschmtbl2( id int primary key, a int unique);
! CREATE TABLE schm3.testschmtbl2( id int primary key, a int unique);
! CREATE TABLE schm3.testschmtbl3( id int primary key, a int unique);
! set search_path to schm2, schm3, public, schm1;
! SHOW search_path;
! 
! --Should not cause any error
! --Insert values into schm2's testschmtbl
! INSERT INTO testschmtbl (id, a) VALUES ( 2,2);
! 
! SET search_path TO schm1, public;
! --Should be an error.
! --Relation testchmtbl2 doesn't exist in the schm1 schema.
! INSERT INTO testchmtbl2 (id, a) VALUES (2,2);
! SET search_path TO schm1, public, schm3, schm2;
! --Should not be an error
! --Insert values into schm3's testschmtbl2
! INSERT INTO testschmtbl2 (id, a) VALUES (2,2);
! select * from schm2.testschmtbl2;
! select * from schm3.testschmtbl2;
! 
! INSERT INTO testschmtbl3 (id, a) VALUES (2,2);--Should not be an error
! select * from schm3.testschmtbl3;
! 
! --DROP TABLE testschmtbl CASCADE;
! set search_path to schm1, public, schm2, schm3;
! BEGIN;
! TRUNCATE testschmtbl;--This should truncate the schm1's testschmtbl
! COMMIT;
! select * from public.testschmtbl;-- row
! select * from schm1.testschmtbl;--0 row
! select * from schm2.testschmtbl;-- row
! select * from schm3.testschmtbl;-- row
! DROP TABLE public.testschmtbl CASCADE;
! DROP SCHEMA schm1 CASCADE;
! DROP SCHEMA schm2 CASCADE;
! DROP SCHEMA schm3 CASCADE;
! select current_schemas(true);
! 
! --This should show the only schema 'public'
! SHOW search_path;
  
+ --Verify schema_elements
  CREATE SCHEMA test_schema_1
         CREATE UNIQUE INDEX abc_a_idx ON abc (a)
  
+        CREATE SEQUENCE abc_seq START WITH 1 INCREMENT BY 2
+ 
         CREATE VIEW abc_view AS
                SELECT a+1 AS a, b+1 AS b FROM abc
  
+        CREATE TRIGGER schmtrigger
+       BEFORE INSERT OR UPDATE ON abc
+        FOR EACH ROW
+        EXECUTE PROCEDURE
+        autoinc(b, abc_seq)
+ 
         CREATE TABLE abc (
                a serial,
                b int UNIQUE
***************
*** 17,31 ****
  SELECT COUNT(*) FROM pg_class WHERE relnamespace =
      (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_1');
  
  INSERT INTO test_schema_1.abc DEFAULT VALUES;
  INSERT INTO test_schema_1.abc DEFAULT VALUES;
  INSERT INTO test_schema_1.abc DEFAULT VALUES;
  
  SELECT * FROM test_schema_1.abc;
  SELECT * FROM test_schema_1.abc_view;
  
  DROP SCHEMA test_schema_1 CASCADE;
  
  -- verify that the objects were dropped
  SELECT COUNT(*) FROM pg_class WHERE relnamespace =
!     (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_1');
--- 110,197 ----
  SELECT COUNT(*) FROM pg_class WHERE relnamespace =
      (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_1');
  
+ --The following query will fail because the schema test_schema_1 is not
+ -- on the search_path yet.
  INSERT INTO test_schema_1.abc DEFAULT VALUES;
+ SELECT nextval('test_schema_1.abc_seq');
+ set search_path to test_schema_1, public;
  INSERT INTO test_schema_1.abc DEFAULT VALUES;
  INSERT INTO test_schema_1.abc DEFAULT VALUES;
  
  SELECT * FROM test_schema_1.abc;
  SELECT * FROM test_schema_1.abc_view;
  
+ SET search_path to test_schema_1, public;
+ 
+ ALTER SCHEMA test_schema_1 RENAME TO test_schema_2;
+ SELECT COUNT(*) FROM pg_class WHERE relnamespace =
+     (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_1');
+ 
+ SELECT COUNT(*) FROM pg_class WHERE relnamespace =
+     (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_2');
+ 
+ SELECT * FROM test_schema_2.abc;
+ SELECT * FROM test_schema_2.abc_view;
+ 
+ --The schema name in the search_path should be altered.
+ SHOW search_path;
+ 
  DROP SCHEMA test_schema_1 CASCADE;
+ DROP SCHEMA test_schema_2 CASCADE;
  
  -- verify that the objects were dropped
  SELECT COUNT(*) FROM pg_class WHERE relnamespace =
!     (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_2');
! 
! -- Verify priviledge
! CREATE USER NSTESTER1;
! CREATE USER NSTESTER2;
! CREATE USER NSTESTER3;
! CREATE SCHEMA AUTHORIZATION nstester1;
! CREATE SCHEMA AUTHORIZATION nstester2;
! CREATE SCHEMA schm3 AUTHORIZATION nstester3;
! ALTER SCHEMA schm3 OWNER TO nstester2;
! GRANT USAGE ON SCHEMA nstester1 TO nstester1;
! SET SESSION AUTHORIZATION nstester1;
! CREATE TABLE nstester2.testtbl ( a int unique);
! SET SESSION AUTHORIZATION nstester2;
! SELECT session_user, current_user;
! GRANT ALL ON SCHEMA nstester2 TO nstester1;
! SET SESSION AUTHORIZATION nstester1;
! CREATE TABLE nstester2.testtbl ( a int unique);
! RESET SESSION AUTHORIZATION;
! DROP USER nstester1;
! DROP USER nstester2;
! DROP USER nstester3;
! DROP SCHEMA nstester1 CASCADE;
! DROP SCHEMA nstester2 CASCADE;
! DROP SCHEMA schm3 CASCADE;
! set search_path to public;
! 
! --test build-in visibility-functions
! CREATE SCHEMA testvisibleschm;
! CREATE TABLE testvisibleschm.mytable ( a int);
! CREATE TYPE testvisibleschm.mytype AS (a int, b int);
! CREATE FUNCTION testvisibleschm.myfunc ( integer, integer ) RETURNS integer
! AS $$select $1 + $2; $$ LANGUAGE SQL;
! CREATE OPERATOR testvisibleschm.^=^ (
! 	leftarg = int4, rightarg = int4,
! 	procedure = testvisibleschm.myfunc
! );
! 
! 
! SELECT pg_table_is_visible('testvisibleschm.mytable'::regclass) as table,
! pg_type_is_visible('testvisibleschm.mytype'::regtype) as type,
! pg_function_is_visible('testvisibleschm.myfunc'::regproc) as func,
! pg_operator_is_visible('testvisibleschm.^=^'::regoper) as opr;
! 
! SET search_path to testvisibleschm;
! 
! SELECT pg_table_is_visible('testvisibleschm.mytable'::regclass) as table,
! pg_type_is_visible('testvisibleschm.mytype'::regtype) as type,
! pg_function_is_visible('myfunc'::regproc) as func,
! pg_operator_is_visible('^=^'::regoper) as opr;
! 
! DROP SCHEMA testvisibleschm CASCADE;
! 
! set search_path to public;
