# Makefile for tutorial
#
# 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 $
#
#-------------------------------------------------------------------------
DLOBJS= complex$(DLSUFFIX) funcs$(DLSUFFIX)
QUERIES= advanced.sql basics.sql complex.sql funcs.sql syscat.sql
+
+INFILES= $(DLOBJS)
+
#
# plus exports files
#
ifdef EXPSUFF
-DLOBJS+= $(DLOBJS:.o=$(EXPSUFF))
+INFILES+= $(DLOBJS:.o=$(EXPSUFF))
endif
all: $(QUERIES)
-e "s:_DLSUFFIX_:$(DLSUFFIX):g" \
-e "s/_USER_/$$USER/g" < $< > $@
-funcs.sql:: $(DLOBJS)
+funcs.sql: $(INFILES)
-$(DLOBJS):
+$(INFILES):
$(MAKE) -C C-code $@
cp C-code/$@ .
clean:
$(MAKE) -C C-code clean
- rm -f $(QUERIES)
- rm -f $(DLOBJS)
+ rm -f $(QUERIES) $(INFILES)
--
-- 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 $
--
---------------------------------------------------------------------------
name text,
population float8,
altitude int -- (in ft)
-)
+);
CREATE TABLE capitals (
state char2
) INHERITS (cities);
-- now, let's populate the tables
-INSERT INTO cities VALUES ('San Francisco', 7.24E+5, 63)
-INSERT INTO cities VALUES ('Las Vegas', 2.583E+5, 2174)
-INSERT INTO cities VALUES ('Mariposa', 1200, 1953)
+INSERT INTO cities VALUES ('San Francisco', 7.24E+5, 63);
+INSERT INTO cities VALUES ('Las Vegas', 2.583E+5, 2174);
+INSERT INTO cities VALUES ('Mariposa', 1200, 1953);
-INSERT INTO capitals VALUES ('Sacramento', 3.694E+5, 30, 'CA')
-INSERT INTO capitals VALUES ('Madison', 1.913E+5, 845, 'WI')
+INSERT INTO capitals VALUES ('Sacramento', 3.694E+5, 30, 'CA');
+INSERT INTO capitals VALUES ('Madison', 1.913E+5, 845, 'WI');
-SELECT * FROM cities
+SELECT * FROM cities;
SELECT * FROM capitals;
-- like before, a regular query references rows of the base table only
-----------------------------
-- Time Travel:
-- 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
-- population grows 10% this year)
-UPDATE cities
-SET population = population * 1.1
-WHERE name = 'Mariposa';
+-- UPDATE cities
+-- SET population = population * 1.1
+-- WHERE name = 'Mariposa';
-- 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
-- earliest time representable by the system)
-SELECT name, population
-FROM cities['epoch', 'now'] -- can be abbreviated to cities[,]
-WHERE name = 'Mariposa';
+-- SELECT name, population
+-- FROM cities['epoch', 'now'] -- can be abbreviated to cities[,]
+-- WHERE name = 'Mariposa';
----------------------
INSERT INTO sal_emp VALUES (
'Bill',
'{10000,10000,10000,10000}',
- '{{"meeting", "lunch"}, {}}')
+ '{{"meeting", "lunch"}, {}}');
INSERT INTO sal_emp VALUES (
'Carol',
-- clean up (you must remove the children first)
-DROP TABLE sal_emp
-DROP TABLE capitals
+DROP TABLE sal_emp;
+DROP TABLE capitals;
DROP TABLE cities;
--
-- 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 $
--
---------------------------------------------------------------------------
-- data for user-defined type are just strings in the proper textual
-- representation.
-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 ('(1.0, 2.5)', '(4.2, 3.55 )');
+INSERT INTO test_complex VALUES ('(33.0, 51.4)', '(100.42, 93.55)');
SELECT * FROM test_complex;
-- first, define the required operators
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
- AS '_OBJWD_/complex.so' LANGUAGE 'c'
+ AS '_OBJWD_/complex.so' LANGUAGE 'c';
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
- AS '_OBJWD_/complex.so' LANGUAGE 'c'
+ AS '_OBJWD_/complex.so' LANGUAGE 'c';
CREATE FUNCTION complex_abs_gt(complex, complex) RETURNS bool
AS '_OBJWD_/complex.so' LANGUAGE 'c';
CREATE OPERATOR < (
leftarg = complex, rightarg = complex, procedure = complex_abs_lt,
restrict = intltsel, join = intltjoinsel
-)
+);
CREATE OPERATOR <= (
leftarg = complex, rightarg = complex, procedure = complex_abs_le,
restrict = intltsel, join = intltjoinsel
-)
+);
CREATE OPERATOR = (
leftarg = complex, rightarg = complex, procedure = complex_abs_eq,
restrict = eqsel, join = eqjoinsel
-)
+);
CREATE OPERATOR >= (
leftarg = complex, rightarg = complex, procedure = complex_abs_ge,
restrict = intgtsel, join = intgtjoinsel
-)
+);
CREATE OPERATOR > (
leftarg = complex, rightarg = complex, procedure = complex_abs_gt,
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';
-- 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
-- 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)');
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)';
+
+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;
--
-- 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 $
--
---------------------------------------------------------------------------
-- lists all left unary operators
--
SELECT o.oprname AS left_unary,
- right.typname AS operand,
+ right_type.typname AS operand,
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
- and o.oprright = right.oid
+ and o.oprright = right_type.oid
and o.oprresult = result.oid
ORDER BY operand;
-- lists all right unary operators
--
SELECT o.oprname AS right_unary,
- left.typname AS operand,
+ left_type.typname AS operand,
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
- and o.oprleft = left.oid
+ and o.oprleft = left_type.oid
and o.oprresult = result.oid
ORDER BY operand;
-- lists all binary operators
--
SELECT o.oprname AS binary_op,
- left.typname AS left_opr,
- right.typname AS right_opr,
+ left_type.typname AS left_opr,
+ right_type.typname AS right_opr,
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
- and o.oprleft = left.oid
- and o.oprright = right.oid
+ and o.oprleft = left_type.oid
+ and o.oprright = right_type.oid
and o.oprresult = result.oid
ORDER BY left_opr, right_opr;