Skip to content
Snippets Groups Projects
Commit 5b3e78af authored by Marc G. Fournier's avatar Marc G. Fournier
Browse files

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.
parent bc58c586
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# Makefile for tutorial # Makefile for tutorial
# #
# IDENTIFICATION # IDENTIFICATION
# $Header: /cvsroot/pgsql/src/tutorial/Makefile,v 1.6 1998/01/04 19:12:55 scrappy Exp $ # $Header: /cvsroot/pgsql/src/tutorial/Makefile,v 1.7 1998/02/28 23:37:07 scrappy Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -28,11 +28,14 @@ endif ...@@ -28,11 +28,14 @@ endif
DLOBJS= complex$(DLSUFFIX) funcs$(DLSUFFIX) DLOBJS= complex$(DLSUFFIX) funcs$(DLSUFFIX)
QUERIES= advanced.sql basics.sql complex.sql funcs.sql syscat.sql QUERIES= advanced.sql basics.sql complex.sql funcs.sql syscat.sql
INFILES= $(DLOBJS)
# #
# plus exports files # plus exports files
# #
ifdef EXPSUFF ifdef EXPSUFF
DLOBJS+= $(DLOBJS:.o=$(EXPSUFF)) INFILES+= $(DLOBJS:.o=$(EXPSUFF))
endif endif
all: $(QUERIES) all: $(QUERIES)
...@@ -48,13 +51,12 @@ all: $(QUERIES) ...@@ -48,13 +51,12 @@ all: $(QUERIES)
-e "s:_DLSUFFIX_:$(DLSUFFIX):g" \ -e "s:_DLSUFFIX_:$(DLSUFFIX):g" \
-e "s/_USER_/$$USER/g" < $< > $@ -e "s/_USER_/$$USER/g" < $< > $@
funcs.sql:: $(DLOBJS) funcs.sql: $(INFILES)
$(DLOBJS): $(INFILES):
$(MAKE) -C C-code $@ $(MAKE) -C C-code $@
cp C-code/$@ . cp C-code/$@ .
clean: clean:
$(MAKE) -C C-code clean $(MAKE) -C C-code clean
rm -f $(QUERIES) rm -f $(QUERIES) $(INFILES)
rm -f $(DLOBJS)
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
-- --
-- Copyright (c) 1994, Regents of the University of California -- Copyright (c) 1994, Regents of the University of California
-- --
-- $Id: advanced.source,v 1.1.1.1 1996/07/09 06:22:34 scrappy Exp $ -- $Id: advanced.source,v 1.2 1998/02/28 23:37:08 scrappy Exp $
-- --
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
...@@ -25,21 +25,21 @@ CREATE TABLE cities ( ...@@ -25,21 +25,21 @@ CREATE TABLE cities (
name text, name text,
population float8, population float8,
altitude int -- (in ft) altitude int -- (in ft)
) );
CREATE TABLE capitals ( CREATE TABLE capitals (
state char2 state char2
) INHERITS (cities); ) INHERITS (cities);
-- now, let's populate the tables -- now, let's populate the tables
INSERT INTO cities VALUES ('San Francisco', 7.24E+5, 63) INSERT INTO cities VALUES ('San Francisco', 7.24E+5, 63);
INSERT INTO cities VALUES ('Las Vegas', 2.583E+5, 2174) INSERT INTO cities VALUES ('Las Vegas', 2.583E+5, 2174);
INSERT INTO cities VALUES ('Mariposa', 1200, 1953) INSERT INTO cities VALUES ('Mariposa', 1200, 1953);
INSERT INTO capitals VALUES ('Sacramento', 3.694E+5, 30, 'CA') INSERT INTO capitals VALUES ('Sacramento', 3.694E+5, 30, 'CA');
INSERT INTO capitals VALUES ('Madison', 1.913E+5, 845, 'WI') INSERT INTO capitals VALUES ('Madison', 1.913E+5, 845, 'WI');
SELECT * FROM cities SELECT * FROM cities;
SELECT * FROM capitals; SELECT * FROM capitals;
-- like before, a regular query references rows of the base table only -- like before, a regular query references rows of the base table only
...@@ -59,25 +59,27 @@ WHERE c.altitude > 500; ...@@ -59,25 +59,27 @@ WHERE c.altitude > 500;
----------------------------- -----------------------------
-- Time Travel: -- Time Travel:
-- this feature allows you to run historical queries. -- this feature allows you to run historical queries.
-- removed for v6.3, but possible using triggers.
-- see contrib/spi/README for more information.
----------------------------- -----------------------------
-- first, let's make some changes to the cities table (suppose Mariposa's -- first, let's make some changes to the cities table (suppose Mariposa's
-- population grows 10% this year) -- population grows 10% this year)
UPDATE cities -- UPDATE cities
SET population = population * 1.1 -- SET population = population * 1.1
WHERE name = 'Mariposa'; -- WHERE name = 'Mariposa';
-- the default time is the current time ('now'): -- the default time is the current time ('now'):
SELECT * FROM cities WHERE name = 'Mariposa'; -- SELECT * FROM cities WHERE name = 'Mariposa';
-- we can also retrieve the population of Mariposa ever has. ('epoch' is the -- we can also retrieve the population of Mariposa ever has. ('epoch' is the
-- earliest time representable by the system) -- earliest time representable by the system)
SELECT name, population -- SELECT name, population
FROM cities['epoch', 'now'] -- can be abbreviated to cities[,] -- FROM cities['epoch', 'now'] -- can be abbreviated to cities[,]
WHERE name = 'Mariposa'; -- WHERE name = 'Mariposa';
---------------------- ----------------------
...@@ -96,7 +98,7 @@ CREATE TABLE sal_emp ( ...@@ -96,7 +98,7 @@ CREATE TABLE sal_emp (
INSERT INTO sal_emp VALUES ( INSERT INTO sal_emp VALUES (
'Bill', 'Bill',
'{10000,10000,10000,10000}', '{10000,10000,10000,10000}',
'{{"meeting", "lunch"}, {}}') '{{"meeting", "lunch"}, {}}');
INSERT INTO sal_emp VALUES ( INSERT INTO sal_emp VALUES (
'Carol', 'Carol',
...@@ -120,6 +122,6 @@ SELECT sal_emp.schedule[1:2][1:1] FROM sal_emp WHERE ...@@ -120,6 +122,6 @@ SELECT sal_emp.schedule[1:2][1:1] FROM sal_emp WHERE
-- clean up (you must remove the children first) -- clean up (you must remove the children first)
DROP TABLE sal_emp DROP TABLE sal_emp;
DROP TABLE capitals DROP TABLE capitals;
DROP TABLE cities; DROP TABLE cities;
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
-- --
-- Copyright (c) 1994, Regents of the University of California -- Copyright (c) 1994, Regents of the University of California
-- --
-- $Id: complex.source,v 1.2 1996/12/28 02:22:07 momjian Exp $ -- $Id: complex.source,v 1.3 1998/02/28 23:37:09 scrappy Exp $
-- --
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
...@@ -64,8 +64,8 @@ CREATE TABLE test_complex ( ...@@ -64,8 +64,8 @@ CREATE TABLE test_complex (
-- data for user-defined type are just strings in the proper textual -- data for user-defined type are just strings in the proper textual
-- representation. -- representation.
INSERT INTO test_complex VALUES ('(1.0, 2.5)', '(4.2, 3.55 )') INSERT INTO test_complex VALUES ('(1.0, 2.5)', '(4.2, 3.55 )');
INSERT INTO test_complex VALUES ('(33.0, 51.4)', '(100.42, 93.55)') INSERT INTO test_complex VALUES ('(33.0, 51.4)', '(100.42, 93.55)');
SELECT * FROM test_complex; SELECT * FROM test_complex;
...@@ -138,13 +138,13 @@ SELECT 'READ ABOVE!' AS STOP; ...@@ -138,13 +138,13 @@ SELECT 'READ ABOVE!' AS STOP;
-- first, define the required operators -- first, define the required operators
CREATE FUNCTION complex_abs_lt(complex, complex) RETURNS bool CREATE FUNCTION complex_abs_lt(complex, complex) RETURNS bool
AS '_OBJWD_/complex.so' LANGUAGE 'c' AS '_OBJWD_/complex.so' LANGUAGE 'c';
CREATE FUNCTION complex_abs_le(complex, complex) RETURNS bool CREATE FUNCTION complex_abs_le(complex, complex) RETURNS bool
AS '_OBJWD_/complex.so' LANGUAGE 'c' AS '_OBJWD_/complex.so' LANGUAGE 'c';
CREATE FUNCTION complex_abs_eq(complex, complex) RETURNS bool CREATE FUNCTION complex_abs_eq(complex, complex) RETURNS bool
AS '_OBJWD_/complex.so' LANGUAGE 'c' AS '_OBJWD_/complex.so' LANGUAGE 'c';
CREATE FUNCTION complex_abs_ge(complex, complex) RETURNS bool CREATE FUNCTION complex_abs_ge(complex, complex) RETURNS bool
AS '_OBJWD_/complex.so' LANGUAGE 'c' AS '_OBJWD_/complex.so' LANGUAGE 'c';
CREATE FUNCTION complex_abs_gt(complex, complex) RETURNS bool CREATE FUNCTION complex_abs_gt(complex, complex) RETURNS bool
AS '_OBJWD_/complex.so' LANGUAGE 'c'; AS '_OBJWD_/complex.so' LANGUAGE 'c';
...@@ -153,25 +153,25 @@ CREATE FUNCTION complex_abs_gt(complex, complex) RETURNS bool ...@@ -153,25 +153,25 @@ CREATE FUNCTION complex_abs_gt(complex, complex) RETURNS bool
CREATE OPERATOR < ( CREATE OPERATOR < (
leftarg = complex, rightarg = complex, procedure = complex_abs_lt, leftarg = complex, rightarg = complex, procedure = complex_abs_lt,
restrict = intltsel, join = intltjoinsel restrict = intltsel, join = intltjoinsel
) );
CREATE OPERATOR <= ( CREATE OPERATOR <= (
leftarg = complex, rightarg = complex, procedure = complex_abs_le, leftarg = complex, rightarg = complex, procedure = complex_abs_le,
restrict = intltsel, join = intltjoinsel restrict = intltsel, join = intltjoinsel
) );
CREATE OPERATOR = ( CREATE OPERATOR = (
leftarg = complex, rightarg = complex, procedure = complex_abs_eq, leftarg = complex, rightarg = complex, procedure = complex_abs_eq,
restrict = eqsel, join = eqjoinsel restrict = eqsel, join = eqjoinsel
) );
CREATE OPERATOR >= ( CREATE OPERATOR >= (
leftarg = complex, rightarg = complex, procedure = complex_abs_ge, leftarg = complex, rightarg = complex, procedure = complex_abs_ge,
restrict = intgtsel, join = intgtjoinsel restrict = intgtsel, join = intgtjoinsel
) );
CREATE OPERATOR > ( CREATE OPERATOR > (
leftarg = complex, rightarg = complex, procedure = complex_abs_gt, leftarg = complex, rightarg = complex, procedure = complex_abs_gt,
restrict = intgtsel, join = intgtjoinsel restrict = intgtsel, join = intgtjoinsel
); );
INSERT INTO pg_opclass VALUES ('complex_abs_ops') INSERT INTO pg_opclass VALUES ('complex_abs_ops');
SELECT oid, opcname FROM pg_opclass WHERE opcname = 'complex_abs_ops'; SELECT oid, opcname FROM pg_opclass WHERE opcname = 'complex_abs_ops';
...@@ -241,7 +241,7 @@ INSERT INTO pg_amproc (amid, amopclaid, amproc, amprocnum) ...@@ -241,7 +241,7 @@ INSERT INTO pg_amproc (amid, amopclaid, amproc, amprocnum)
-- now, we can define a btree index on complex types. First, let's populate -- now, we can define a btree index on complex types. First, let's populate
-- the table. Note that postgres needs many more tuples to start using the -- the table. Note that postgres needs many more tuples to start using the
-- btree index during selects. -- btree index during selects.
INSERT INTO test_complex VALUES ('(56.0,-22.5)', '(-43.2,-0.07)') INSERT INTO test_complex VALUES ('(56.0,-22.5)', '(-43.2,-0.07)');
INSERT INTO test_complex VALUES ('(-91.9,33.6)', '(8.6,3.0)'); INSERT INTO test_complex VALUES ('(-91.9,33.6)', '(8.6,3.0)');
CREATE INDEX test_cplx_ind ON test_complex CREATE INDEX test_cplx_ind ON test_complex
...@@ -250,3 +250,22 @@ CREATE INDEX test_cplx_ind ON test_complex ...@@ -250,3 +250,22 @@ CREATE INDEX test_cplx_ind ON test_complex
SELECT * from test_complex where a = '(56.0,-22.5)'; SELECT * from test_complex where a = '(56.0,-22.5)';
SELECT * from test_complex where a < '(56.0,-22.5)'; SELECT * from test_complex where a < '(56.0,-22.5)';
SELECT * from test_complex where a > '(56.0,-22.5)'; SELECT * from test_complex where a > '(56.0,-22.5)';
DROP FUNCTION complex_in(opaque);
DROP FUNCTION complex_out(opaque);
DROP FUNCTION complex_add(complex, complex);
DROP FUNCTION complex_abs_lt(complex, complex);
DROP FUNCTION complex_abs_le(complex, complex);
DROP FUNCTION complex_abs_eq(complex, complex);
DROP FUNCTION complex_abs_ge(complex, complex);
DROP FUNCTION complex_abs_gt(complex, complex);
DROP FUNCTION complex_abs_cmp(complex, complex);
DROP OPERATOR + (complex, complex);
DROP OPERATOR < (complex, complex);
DROP OPERATOR <= (complex, complex);
DROP OPERATOR = (complex, complex);
DROP OPERATOR >= (complex, complex);
DROP OPERATOR > (complex, complex);
DROP AGGREGATE complex_sum complex;
DROP TYPE complex;
DROP TABLE test_complex;
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- --
-- Copyright (c) 1994, Regents of the University of California -- Copyright (c) 1994, Regents of the University of California
-- --
-- $Id: syscat.source,v 1.1.1.1 1996/07/09 06:22:34 scrappy Exp $ -- $Id: syscat.source,v 1.2 1998/02/28 23:37:10 scrappy Exp $
-- --
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
...@@ -80,11 +80,11 @@ SELECT u.usename, t.typname ...@@ -80,11 +80,11 @@ SELECT u.usename, t.typname
-- lists all left unary operators -- lists all left unary operators
-- --
SELECT o.oprname AS left_unary, SELECT o.oprname AS left_unary,
right.typname AS operand, right_type.typname AS operand,
result.typname AS return_type result.typname AS return_type
FROM pg_operator o, pg_type right, pg_type result FROM pg_operator o, pg_type right_type, pg_type result
WHERE o.oprkind = 'l' -- left unary WHERE o.oprkind = 'l' -- left unary
and o.oprright = right.oid and o.oprright = right_type.oid
and o.oprresult = result.oid and o.oprresult = result.oid
ORDER BY operand; ORDER BY operand;
...@@ -93,11 +93,11 @@ SELECT o.oprname AS left_unary, ...@@ -93,11 +93,11 @@ SELECT o.oprname AS left_unary,
-- lists all right unary operators -- lists all right unary operators
-- --
SELECT o.oprname AS right_unary, SELECT o.oprname AS right_unary,
left.typname AS operand, left_type.typname AS operand,
result.typname AS return_type result.typname AS return_type
FROM pg_operator o, pg_type left, pg_type result FROM pg_operator o, pg_type left_type, pg_type result
WHERE o.oprkind = 'r' -- right unary WHERE o.oprkind = 'r' -- right unary
and o.oprleft = left.oid and o.oprleft = left_type.oid
and o.oprresult = result.oid and o.oprresult = result.oid
ORDER BY operand; ORDER BY operand;
...@@ -105,13 +105,13 @@ SELECT o.oprname AS right_unary, ...@@ -105,13 +105,13 @@ SELECT o.oprname AS right_unary,
-- lists all binary operators -- lists all binary operators
-- --
SELECT o.oprname AS binary_op, SELECT o.oprname AS binary_op,
left.typname AS left_opr, left_type.typname AS left_opr,
right.typname AS right_opr, right_type.typname AS right_opr,
result.typname AS return_type result.typname AS return_type
FROM pg_operator o, pg_type left, pg_type right, pg_type result FROM pg_operator o, pg_type left_type, pg_type right_type, pg_type result
WHERE o.oprkind = 'b' -- binary WHERE o.oprkind = 'b' -- binary
and o.oprleft = left.oid and o.oprleft = left_type.oid
and o.oprright = right.oid and o.oprright = right_type.oid
and o.oprresult = result.oid and o.oprresult = result.oid
ORDER BY left_opr, right_opr; ORDER BY left_opr, right_opr;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment