summaryrefslogtreecommitdiff
path: root/test/sampletables.sql
blob: d65da90dc019027b08c2ef5dfc3c087e70ec8e10 (plain)
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
-- This file creates some tables to be used in the tests.
--
-- Note that the reset-db program that reads this file is dumb and reads
-- it one line at a time. Hence each statement must be on a single line.

CREATE TABLE testtab1 (id integer PRIMARY KEY, t varchar(20));
INSERT INTO testtab1 VALUES (1, 'foo');
INSERT INTO testtab1 VALUES (2, 'bar');
INSERT INTO testtab1 VALUES (3, 'foobar');

CREATE TABLE testtab_fk (id integer REFERENCES testtab1, t varchar(20));
INSERT INTO testtab_fk VALUES (1, 'hoge');
INSERT INTO testtab_fk VALUES (2, 'pogno');
INSERT INTO testtab_fk VALUES (3, 'poco');

CREATE TABLE byteatab (id integer, t bytea);
INSERT INTO byteatab VALUES (1, E'\\001\\002\\003\\004\\005\\006\\007\\010'::bytea);
INSERT INTO byteatab VALUES (2, 'bar');
INSERT INTO byteatab VALUES (3, 'foobar');
INSERT INTO byteatab VALUES (4, 'foo');
INSERT INTO byteatab VALUES (5, 'barf');

CREATE TABLE intervaltable(id integer, iv interval, d varchar(100));
INSERT INTO intervaltable VALUES (1, '1 day', 'one day');
INSERT INTO intervaltable VALUES (2, '10 seconds', 'ten secs');
INSERT INTO intervaltable VALUES (3, '100 years', 'hundred years');

CREATE TABLE booltab (id integer, t varchar(5), b boolean);
INSERT INTO booltab VALUES (1, 'yeah', true);
INSERT INTO booltab VALUES (2, 'yes', true);
INSERT INTO booltab VALUES (3, 'true', true);
INSERT INTO booltab VALUES (4, 'false', false);
INSERT INTO booltab VALUES (5, 'not', false);

-- View
CREATE VIEW testview AS SELECT * FROM testtab1;

-- Materialized view
CREATE MATERIALIZED VIEW testmatview AS SELECT * FROM testtab1;

-- Foreign table
CREATE FOREIGN DATA WRAPPER testfdw;
CREATE SERVER testserver FOREIGN DATA WRAPPER testfdw;
CREATE FOREIGN TABLE testforeign (c1 int) SERVER testserver;

-- Procedure for catalog function checks
CREATE FUNCTION simple_add(in int, in int, out int) AS $$ SELECT $1 + $2; $$ LANGUAGE SQL;
-- 	Function Returning composite type
CREATE FUNCTION getfoo(int) RETURNS booltab AS $$ SELECT * FROM booltab WHERE id = $1; $$ LANGUAGE SQL;
--	Function Returning set of composite type
CREATE FUNCTION getboo(int) RETURNS SETOF booltab AS $$ SELECT * FROM booltab WHERE id = $1; $$ LANGUAGE SQL;
--	Function Returning table
CREATE FUNCTION tbl_arg(in p_f1 int) returns table(p_f2 text, p_f3 boolean) AS $$ SELECT t, b from booltab where id = p_f1; $$ LANGUAGE SQL;
--	The previous one is equivalent to using one or more OUT parameters
--	plus marking the function as returning SETOF record (or SETOF a single
--	output parameter's type, as appropriate).
CREATE FUNCTION set_of(in p_f1 int, out p_f2 text, out p_f3 boolean) returns setof record AS $$ SELECT t, b from booltab where id = p_f1; $$ LANGUAGE SQL;

-- Large object support
CREATE DOMAIN lo AS oid;
CREATE TABLE lo_test_tab (id int4, large_data lo);