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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
--
-- PostgreSQL database dump
--
SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;
--
-- Name: anotherschema; Type: SCHEMA; Schema: -; Owner: -
--
DROP SCHEMA IF EXISTS anotherschema CASCADE;
CREATE SCHEMA anotherschema;
SET search_path = anotherschema, pg_catalog;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- Name: users; Type: TABLE; Schema: anotherschema; Owner: -; Tablespace:
--
DROP TABLE IF EXISTS users CASCADE;
CREATE TABLE users (
name character varying(30),
email character varying(50),
created_at timestamp without time zone DEFAULT now(),
id integer NOT NULL
);
--
-- Name: users_id_seq; Type: SEQUENCE; Schema: anotherschema; Owner: -
--
CREATE SEQUENCE users_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: anotherschema; Owner: -
--
ALTER SEQUENCE users_id_seq OWNED BY users.id;
SET search_path = public, pg_catalog;
--
-- Name: seqnames; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
DROP TABLE IF EXISTS seqnames CASCADE;
CREATE TABLE seqnames (
name character varying(30),
pk_id integer NOT NULL
);
--
-- Name: users_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE seqnames_pk_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: seqnames_pk_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE seqnames_pk_id_seq OWNED BY seqnames.pk_id;
--
-- Name: empty_table; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
DROP TABLE IF EXISTS empty_table CASCADE;
CREATE TABLE empty_table (
id integer NOT NULL,
field character varying
);
--
-- Name: empty_table_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE empty_table_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: empty_table_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE empty_table_id_seq OWNED BY empty_table.id;
--
-- Name: groups; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
DROP TABLE IF EXISTS groups CASCADE;
CREATE TABLE groups (
name character varying(50),
enabled boolean,
created_at timestamp without time zone DEFAULT now(),
id integer NOT NULL
);
--
-- Name: groups_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE groups_id_seq
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
--
-- Name: groups_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE groups_id_seq OWNED BY groups.id;
--
-- Name: permissions; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
DROP TABLE IF EXISTS permissions CASCADE;
CREATE TABLE permissions (
user_id integer,
group_id integer,
role character varying(10),
id integer NOT NULL
);
--
-- Name: permissions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE permissions_id_seq
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
--
-- Name: permissions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE permissions_id_seq OWNED BY permissions.id;
--
-- Name: users; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
DROP TABLE IF EXISTS users CASCADE;
CREATE TABLE users (
name character varying(30),
email character varying(50),
created_at timestamp without time zone DEFAULT now(),
id integer NOT NULL
);
--
-- Name: users_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE users_id_seq
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
--
-- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE users_id_seq OWNED BY users.id;
SET search_path = anotherschema, pg_catalog;
--
-- Name: id; Type: DEFAULT; Schema: anotherschema; Owner: -
--
ALTER TABLE ONLY users ALTER COLUMN id SET DEFAULT nextval('users_id_seq'::regclass);
SET search_path = public, pg_catalog;
--
-- Name:pk_id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY seqnames ALTER COLUMN pk_id SET DEFAULT nextval('seqnames_pk_id_seq'::regclass);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY empty_table ALTER COLUMN id SET DEFAULT nextval('empty_table_id_seq'::regclass);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY groups ALTER COLUMN id SET DEFAULT nextval('groups_id_seq'::regclass);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY permissions ALTER COLUMN id SET DEFAULT nextval('permissions_id_seq'::regclass);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY users ALTER COLUMN id SET DEFAULT nextval('users_id_seq'::regclass);
SET search_path = anotherschema, pg_catalog;
--
-- Data for Name: users; Type: TABLE DATA; Schema: anotherschema; Owner: -
--
COPY users (name, email, created_at, id) FROM stdin;
andrew schemauser@example.org 2015-10-13 07:26:51.398693 1
\.
--
-- Name: users_id_seq; Type: SEQUENCE SET; Schema: anotherschema; Owner: -
--
SELECT pg_catalog.setval('users_id_seq', 1, true);
SET search_path = public, pg_catalog;
--
-- Data for Name: empty_table; Type: TABLE DATA; Schema: public; Owner: -
--
COPY empty_table (id, field) FROM stdin;
\.
--
-- Name: seqnames_pk_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--
SELECT pg_catalog.setval('seqnames_pk_id_seq', 1, false);
--
-- Name: empty_table_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--
SELECT pg_catalog.setval('empty_table_id_seq', 1, false);
--
-- Data for Name: groups; Type: TABLE DATA; Schema: public; Owner: -
--
COPY groups (name, enabled, created_at, id) FROM stdin;
coders t 2012-02-02 22:33:30.807 1
jazzman f 2012-02-02 22:33:35.271 2
\.
--
-- Name: groups_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--
SELECT pg_catalog.setval('groups_id_seq', 2, true);
--
-- Data for Name: permissions; Type: TABLE DATA; Schema: public; Owner: -
--
COPY permissions (user_id, group_id, role, id) FROM stdin;
1 1 member 1
2 1 member 2
3 2 member 9
4 2 admin 10
\.
--
-- Name: permissions_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--
SELECT pg_catalog.setval('permissions_id_seq', 10, true);
--
-- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: -
--
COPY users (name, email, created_at, id) FROM stdin;
davert davert@mail.ua \N 1
nick nick@mail.ua 2012-02-02 22:30:31.748 2
miles miles@davis.com 2012-02-02 22:30:52.166 3
bird charlie@parker.com 2012-02-02 22:32:13.107 4
\.
--
-- Name: users_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--
SELECT pg_catalog.setval('users_id_seq', 4, true);
SET search_path = anotherschema, pg_catalog;
--
-- Name: u1; Type: CONSTRAINT; Schema: anotherschema; Owner: -; Tablespace:
--
ALTER TABLE ONLY users
ADD CONSTRAINT u1 PRIMARY KEY (id);
SET search_path = public, pg_catalog;
--
-- Name: g1; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY seqnames
ADD CONSTRAINT s1 PRIMARY KEY (pk_id);
--
-- Name: g1; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY groups
ADD CONSTRAINT g1 PRIMARY KEY (id);
--
-- Name: p1; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY permissions
ADD CONSTRAINT p1 PRIMARY KEY (id);
--
-- Name: u1; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY users
ADD CONSTRAINT u1 PRIMARY KEY (id);
--
-- Name: pf1; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY permissions
ADD CONSTRAINT pf1 FOREIGN KEY (user_id) REFERENCES users(id);
--
-- Name: pg1; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY permissions
ADD CONSTRAINT pg1 FOREIGN KEY (group_id) REFERENCES groups(id);
--
-- start test for triggers with $$ syntax
--
INSERT INTO users (name, email) VALUES ('This $$ should work', 'user@example.org');
CREATE OR REPLACE FUNCTION upd_timestamp() RETURNS TRIGGER
LANGUAGE plpgsql
AS
$$
BEGIN
NEW.created_at = CURRENT_TIMESTAMP;
RETURN NEW;
END;
$$;
-- Test $$ opening quote when is not at the beginning of the line.
CREATE OR REPLACE FUNCTION upd_timestamp() RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
BEGIN
NEW.created_at = CURRENT_TIMESTAMP;
RETURN NEW;
END;
$$;
INSERT INTO users (name, email) VALUES ('This should work as well', 'user2@example.org');
--
-- end test for triggers with $$ syntax
--
CREATE TABLE "composite_pk" (
"group_id" INTEGER NOT NULL,
"id" INTEGER NOT NULL,
"status" VARCHAR NOT NULL,
PRIMARY KEY ("group_id", "id")
);
CREATE TABLE "no_pk" (
"status" VARCHAR NOT NULL
);
CREATE TABLE "order" (
"id" INTEGER NOT NULL PRIMARY KEY,
"name" VARCHAR NOT NULL,
"status" VARCHAR NOT NULL
);
insert into "order"("id","name","status") values (1,'main', 'open');
-- Custom Types
DROP TYPE IF EXISTS composite_type;
CREATE TYPE composite_type AS (
a decimal,
b decimal
);
DROP TYPE IF EXISTS enum_type;
CREATE TYPE enum_type AS ENUM (
'Mon',
'Tue',
'Wed',
'Thu',
'Fri',
'Sat',
'Sun'
);
DROP TYPE IF EXISTS range_type;
CREATE TYPE range_type AS range (subtype = time);
DROP TYPE IF EXISTS base_type;
CREATE TYPE base_type;
-- --
-- PostgreSQL database dump complete
--