/
commands.out
180 lines (155 loc) · 4.18 KB
/
commands.out
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
* Copyright 2020 Bitnine Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
--
-- Initial setup
--
LOAD 'agensgraph';
SET search_path TO ag_catalog;
--
-- create_graph() and drop_graph() tests.
--
SELECT create_graph('g');
NOTICE: graph "g" has been created
create_graph
--------------
(1 row)
SELECT count(*) FROM ag_graph WHERE name = 'g';
count
-------
1
(1 row)
SELECT count(*) FROM pg_namespace WHERE nspname = 'g';
count
-------
1
(1 row)
-- Create a temporary table to test drop_graph().
CREATE TABLE g.tmp (i int);
SELECT drop_graph('g');
ERROR: cannot drop schema g because other objects depend on it
DETAIL: table g.tmp depends on schema g
HINT: Use DROP ... CASCADE to drop the dependent objects too.
SELECT drop_graph('g', true);
NOTICE: drop cascades to table g.tmp
NOTICE: graph "g" has been dropped
drop_graph
------------
(1 row)
SELECT count(*) FROM pg_namespace WHERE nspname = 'g';
count
-------
0
(1 row)
SELECT count(*) FROM ag_graph WHERE name = 'g';
count
-------
0
(1 row)
SELECT create_graph(NULL);
ERROR: graph name must not be NULL
SELECT drop_graph(NULL);
ERROR: graph name must not be NULL
--
-- alter_graph() RENAME function test.
--
-- Create 2 graphs for test.
SELECT create_graph('GraphA');
NOTICE: graph "GraphA" has been created
create_graph
--------------
(1 row)
SELECT create_graph('GraphB');
NOTICE: graph "GraphB" has been created
create_graph
--------------
(1 row)
-- Show GraphA's construction to verify case is preserved.
SELECT * FROM ag_graph WHERE name = 'GraphA';
name | namespace
--------+-----------
GraphA | "GraphA"
(1 row)
SELECT nspname FROM pg_namespace WHERE nspname = 'GraphA';
nspname
---------
GraphA
(1 row)
-- Rename GraphA to GraphX.
SELECT alter_graph('GraphA', 'RENAME', 'GraphX');
NOTICE: graph "GraphA" renamed to "GraphX"
alter_graph
-------------
(1 row)
-- Show GraphX's construction to verify case is preserved.
SELECT * FROM ag_graph WHERE name = 'GraphX';
name | namespace
--------+-----------
GraphX | "GraphX"
(1 row)
SELECT nspname FROM pg_namespace WHERE nspname = 'GraphX';
nspname
---------
GraphX
(1 row)
-- Verify there isn't a graph GraphA anymore.
SELECT * FROM ag_graph WHERE name = 'GraphA';
name | namespace
------+-----------
(0 rows)
SELECT * FROM pg_namespace WHERE nspname = 'GraphA';
nspname | nspowner | nspacl
---------+----------+--------
(0 rows)
-- Sanity check that graphx does not exist - should return 0.
SELECT count(*) FROM ag_graph where name = 'graphx';
count
-------
0
(1 row)
-- Verify case sensitivity (graphx does not exist, but GraphX does) - should fail.
SELECT alter_graph('graphx', 'RENAME', 'GRAPHX');
ERROR: schema "graphx" does not exist
-- Checks for collisions (GraphB already exists) - should fail.
SELECT alter_graph('GraphX', 'RENAME', 'GraphB');
ERROR: schema "GraphB" already exists
-- Remove graphs.
SELECT drop_graph('GraphX');
NOTICE: graph "GraphX" has been dropped
drop_graph
------------
(1 row)
SELECT drop_graph('GraphB');
NOTICE: graph "GraphB" has been dropped
drop_graph
------------
(1 row)
-- Verify that renaming a graph that does not exist fails.
SELECT alter_graph('GraphB', 'RENAME', 'GraphA');
ERROR: schema "GraphB" does not exist
-- Verify NULL input checks.
SELECT alter_graph(NULL, 'RENAME', 'GraphA');
ERROR: graph_name must not be NULL
SELECT alter_graph('GraphB', NULL, 'GraphA');
ERROR: operation must not be NULL
SELECT alter_graph('GraphB', 'RENAME', NULL);
ERROR: new_value must not be NULL
-- Verify invalid input check for operation parameter.
SELECT alter_graph('GraphB', 'DUMMY', 'GraphA');
ERROR: invalid operation "DUMMY"
HINT: valid operations: RENAME
--
-- End tests
--