Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5b3e78a

Browse files
committed
From: Darren King <darrenk@insightdist.com>
Seem to remember someone posting to one of the lists a while back that the tutorial code wouldn't compile and/or run. Found four problems with it that will let it run. 1. Tutorial makefile had a recursive use of DLOBJS. 2. Some tutorial needed semi-colons added to many statements. 3. Complex tutorial didn't clean up after itself. 4. Advanced had a time-travel example. Commented it out and put a line pointing the user to contrib/spi/README.
1 parent bc58c58 commit 5b3e78a

File tree

4 files changed

+72
-49
lines changed

4 files changed

+72
-49
lines changed

src/tutorial/Makefile

+8-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Makefile for tutorial
55
#
66
# IDENTIFICATION
7-
# $Header: /cvsroot/pgsql/src/tutorial/Makefile,v 1.6 1998/01/04 19:12:55 scrappy Exp $
7+
# $Header: /cvsroot/pgsql/src/tutorial/Makefile,v 1.7 1998/02/28 23:37:07 scrappy Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -28,11 +28,14 @@ endif
2828
DLOBJS= complex$(DLSUFFIX) funcs$(DLSUFFIX)
2929

3030
QUERIES= advanced.sql basics.sql complex.sql funcs.sql syscat.sql
31+
32+
INFILES= $(DLOBJS)
33+
3134
#
3235
# plus exports files
3336
#
3437
ifdef EXPSUFF
35-
DLOBJS+= $(DLOBJS:.o=$(EXPSUFF))
38+
INFILES+= $(DLOBJS:.o=$(EXPSUFF))
3639
endif
3740

3841
all: $(QUERIES)
@@ -48,13 +51,12 @@ all: $(QUERIES)
4851
-e "s:_DLSUFFIX_:$(DLSUFFIX):g" \
4952
-e "s/_USER_/$$USER/g" < $< > $@
5053

51-
funcs.sql:: $(DLOBJS)
54+
funcs.sql: $(INFILES)
5255

53-
$(DLOBJS):
56+
$(INFILES):
5457
$(MAKE) -C C-code $@
5558
cp C-code/$@ .
5659

5760
clean:
5861
$(MAKE) -C C-code clean
59-
rm -f $(QUERIES)
60-
rm -f $(DLOBJS)
62+
rm -f $(QUERIES) $(INFILES)

src/tutorial/advanced.source

+20-18
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
--
88
-- Copyright (c) 1994, Regents of the University of California
99
--
10-
-- $Id: advanced.source,v 1.1.1.1 1996/07/09 06:22:34 scrappy Exp $
10+
-- $Id: advanced.source,v 1.2 1998/02/28 23:37:08 scrappy Exp $
1111
--
1212
---------------------------------------------------------------------------
1313

@@ -25,21 +25,21 @@ CREATE TABLE cities (
2525
name text,
2626
population float8,
2727
altitude int -- (in ft)
28-
)
28+
);
2929

3030
CREATE TABLE capitals (
3131
state char2
3232
) INHERITS (cities);
3333

3434
-- now, let's populate the tables
35-
INSERT INTO cities VALUES ('San Francisco', 7.24E+5, 63)
36-
INSERT INTO cities VALUES ('Las Vegas', 2.583E+5, 2174)
37-
INSERT INTO cities VALUES ('Mariposa', 1200, 1953)
35+
INSERT INTO cities VALUES ('San Francisco', 7.24E+5, 63);
36+
INSERT INTO cities VALUES ('Las Vegas', 2.583E+5, 2174);
37+
INSERT INTO cities VALUES ('Mariposa', 1200, 1953);
3838

39-
INSERT INTO capitals VALUES ('Sacramento', 3.694E+5, 30, 'CA')
40-
INSERT INTO capitals VALUES ('Madison', 1.913E+5, 845, 'WI')
39+
INSERT INTO capitals VALUES ('Sacramento', 3.694E+5, 30, 'CA');
40+
INSERT INTO capitals VALUES ('Madison', 1.913E+5, 845, 'WI');
4141

42-
SELECT * FROM cities
42+
SELECT * FROM cities;
4343
SELECT * FROM capitals;
4444

4545
-- like before, a regular query references rows of the base table only
@@ -59,25 +59,27 @@ WHERE c.altitude > 500;
5959
-----------------------------
6060
-- Time Travel:
6161
-- this feature allows you to run historical queries.
62+
-- removed for v6.3, but possible using triggers.
63+
-- see contrib/spi/README for more information.
6264
-----------------------------
6365

6466
-- first, let's make some changes to the cities table (suppose Mariposa's
6567
-- population grows 10% this year)
6668

67-
UPDATE cities
68-
SET population = population * 1.1
69-
WHERE name = 'Mariposa';
69+
-- UPDATE cities
70+
-- SET population = population * 1.1
71+
-- WHERE name = 'Mariposa';
7072

7173
-- the default time is the current time ('now'):
7274

73-
SELECT * FROM cities WHERE name = 'Mariposa';
75+
-- SELECT * FROM cities WHERE name = 'Mariposa';
7476

7577
-- we can also retrieve the population of Mariposa ever has. ('epoch' is the
7678
-- earliest time representable by the system)
7779

78-
SELECT name, population
79-
FROM cities['epoch', 'now'] -- can be abbreviated to cities[,]
80-
WHERE name = 'Mariposa';
80+
-- SELECT name, population
81+
-- FROM cities['epoch', 'now'] -- can be abbreviated to cities[,]
82+
-- WHERE name = 'Mariposa';
8183

8284

8385
----------------------
@@ -96,7 +98,7 @@ CREATE TABLE sal_emp (
9698
INSERT INTO sal_emp VALUES (
9799
'Bill',
98100
'{10000,10000,10000,10000}',
99-
'{{"meeting", "lunch"}, {}}')
101+
'{{"meeting", "lunch"}, {}}');
100102

101103
INSERT INTO sal_emp VALUES (
102104
'Carol',
@@ -120,6 +122,6 @@ SELECT sal_emp.schedule[1:2][1:1] FROM sal_emp WHERE
120122

121123

122124
-- clean up (you must remove the children first)
123-
DROP TABLE sal_emp
124-
DROP TABLE capitals
125+
DROP TABLE sal_emp;
126+
DROP TABLE capitals;
125127
DROP TABLE cities;

src/tutorial/complex.source

+32-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
--
88
-- Copyright (c) 1994, Regents of the University of California
99
--
10-
-- $Id: complex.source,v 1.2 1996/12/28 02:22:07 momjian Exp $
10+
-- $Id: complex.source,v 1.3 1998/02/28 23:37:09 scrappy Exp $
1111
--
1212
---------------------------------------------------------------------------
1313

@@ -64,8 +64,8 @@ CREATE TABLE test_complex (
6464
-- data for user-defined type are just strings in the proper textual
6565
-- representation.
6666

67-
INSERT INTO test_complex VALUES ('(1.0, 2.5)', '(4.2, 3.55 )')
68-
INSERT INTO test_complex VALUES ('(33.0, 51.4)', '(100.42, 93.55)')
67+
INSERT INTO test_complex VALUES ('(1.0, 2.5)', '(4.2, 3.55 )');
68+
INSERT INTO test_complex VALUES ('(33.0, 51.4)', '(100.42, 93.55)');
6969

7070
SELECT * FROM test_complex;
7171

@@ -138,13 +138,13 @@ SELECT 'READ ABOVE!' AS STOP;
138138

139139
-- first, define the required operators
140140
CREATE FUNCTION complex_abs_lt(complex, complex) RETURNS bool
141-
AS '_OBJWD_/complex.so' LANGUAGE 'c'
141+
AS '_OBJWD_/complex.so' LANGUAGE 'c';
142142
CREATE FUNCTION complex_abs_le(complex, complex) RETURNS bool
143-
AS '_OBJWD_/complex.so' LANGUAGE 'c'
143+
AS '_OBJWD_/complex.so' LANGUAGE 'c';
144144
CREATE FUNCTION complex_abs_eq(complex, complex) RETURNS bool
145-
AS '_OBJWD_/complex.so' LANGUAGE 'c'
145+
AS '_OBJWD_/complex.so' LANGUAGE 'c';
146146
CREATE FUNCTION complex_abs_ge(complex, complex) RETURNS bool
147-
AS '_OBJWD_/complex.so' LANGUAGE 'c'
147+
AS '_OBJWD_/complex.so' LANGUAGE 'c';
148148
CREATE FUNCTION complex_abs_gt(complex, complex) RETURNS bool
149149
AS '_OBJWD_/complex.so' LANGUAGE 'c';
150150

@@ -153,25 +153,25 @@ CREATE FUNCTION complex_abs_gt(complex, complex) RETURNS bool
153153
CREATE OPERATOR < (
154154
leftarg = complex, rightarg = complex, procedure = complex_abs_lt,
155155
restrict = intltsel, join = intltjoinsel
156-
)
156+
);
157157
CREATE OPERATOR <= (
158158
leftarg = complex, rightarg = complex, procedure = complex_abs_le,
159159
restrict = intltsel, join = intltjoinsel
160-
)
160+
);
161161
CREATE OPERATOR = (
162162
leftarg = complex, rightarg = complex, procedure = complex_abs_eq,
163163
restrict = eqsel, join = eqjoinsel
164-
)
164+
);
165165
CREATE OPERATOR >= (
166166
leftarg = complex, rightarg = complex, procedure = complex_abs_ge,
167167
restrict = intgtsel, join = intgtjoinsel
168-
)
168+
);
169169
CREATE OPERATOR > (
170170
leftarg = complex, rightarg = complex, procedure = complex_abs_gt,
171171
restrict = intgtsel, join = intgtjoinsel
172172
);
173173

174-
INSERT INTO pg_opclass VALUES ('complex_abs_ops')
174+
INSERT INTO pg_opclass VALUES ('complex_abs_ops');
175175

176176
SELECT oid, opcname FROM pg_opclass WHERE opcname = 'complex_abs_ops';
177177

@@ -241,7 +241,7 @@ INSERT INTO pg_amproc (amid, amopclaid, amproc, amprocnum)
241241
-- now, we can define a btree index on complex types. First, let's populate
242242
-- the table. Note that postgres needs many more tuples to start using the
243243
-- btree index during selects.
244-
INSERT INTO test_complex VALUES ('(56.0,-22.5)', '(-43.2,-0.07)')
244+
INSERT INTO test_complex VALUES ('(56.0,-22.5)', '(-43.2,-0.07)');
245245
INSERT INTO test_complex VALUES ('(-91.9,33.6)', '(8.6,3.0)');
246246

247247
CREATE INDEX test_cplx_ind ON test_complex
@@ -250,3 +250,22 @@ CREATE INDEX test_cplx_ind ON test_complex
250250
SELECT * from test_complex where a = '(56.0,-22.5)';
251251
SELECT * from test_complex where a < '(56.0,-22.5)';
252252
SELECT * from test_complex where a > '(56.0,-22.5)';
253+
254+
DROP FUNCTION complex_in(opaque);
255+
DROP FUNCTION complex_out(opaque);
256+
DROP FUNCTION complex_add(complex, complex);
257+
DROP FUNCTION complex_abs_lt(complex, complex);
258+
DROP FUNCTION complex_abs_le(complex, complex);
259+
DROP FUNCTION complex_abs_eq(complex, complex);
260+
DROP FUNCTION complex_abs_ge(complex, complex);
261+
DROP FUNCTION complex_abs_gt(complex, complex);
262+
DROP FUNCTION complex_abs_cmp(complex, complex);
263+
DROP OPERATOR + (complex, complex);
264+
DROP OPERATOR < (complex, complex);
265+
DROP OPERATOR <= (complex, complex);
266+
DROP OPERATOR = (complex, complex);
267+
DROP OPERATOR >= (complex, complex);
268+
DROP OPERATOR > (complex, complex);
269+
DROP AGGREGATE complex_sum complex;
270+
DROP TYPE complex;
271+
DROP TABLE test_complex;

src/tutorial/syscat.source

+12-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
--
77
-- Copyright (c) 1994, Regents of the University of California
88
--
9-
-- $Id: syscat.source,v 1.1.1.1 1996/07/09 06:22:34 scrappy Exp $
9+
-- $Id: syscat.source,v 1.2 1998/02/28 23:37:10 scrappy Exp $
1010
--
1111
---------------------------------------------------------------------------
1212

@@ -80,11 +80,11 @@ SELECT u.usename, t.typname
8080
-- lists all left unary operators
8181
--
8282
SELECT o.oprname AS left_unary,
83-
right.typname AS operand,
83+
right_type.typname AS operand,
8484
result.typname AS return_type
85-
FROM pg_operator o, pg_type right, pg_type result
85+
FROM pg_operator o, pg_type right_type, pg_type result
8686
WHERE o.oprkind = 'l' -- left unary
87-
and o.oprright = right.oid
87+
and o.oprright = right_type.oid
8888
and o.oprresult = result.oid
8989
ORDER BY operand;
9090

@@ -93,25 +93,25 @@ SELECT o.oprname AS left_unary,
9393
-- lists all right unary operators
9494
--
9595
SELECT o.oprname AS right_unary,
96-
left.typname AS operand,
96+
left_type.typname AS operand,
9797
result.typname AS return_type
98-
FROM pg_operator o, pg_type left, pg_type result
98+
FROM pg_operator o, pg_type left_type, pg_type result
9999
WHERE o.oprkind = 'r' -- right unary
100-
and o.oprleft = left.oid
100+
and o.oprleft = left_type.oid
101101
and o.oprresult = result.oid
102102
ORDER BY operand;
103103

104104
--
105105
-- lists all binary operators
106106
--
107107
SELECT o.oprname AS binary_op,
108-
left.typname AS left_opr,
109-
right.typname AS right_opr,
108+
left_type.typname AS left_opr,
109+
right_type.typname AS right_opr,
110110
result.typname AS return_type
111-
FROM pg_operator o, pg_type left, pg_type right, pg_type result
111+
FROM pg_operator o, pg_type left_type, pg_type right_type, pg_type result
112112
WHERE o.oprkind = 'b' -- binary
113-
and o.oprleft = left.oid
114-
and o.oprright = right.oid
113+
and o.oprleft = left_type.oid
114+
and o.oprright = right_type.oid
115115
and o.oprresult = result.oid
116116
ORDER BY left_opr, right_opr;
117117

0 commit comments

Comments
 (0)