Re: Bug #583: Wrong example in 7.2 Tutorial

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: rainer(dot)tammer(at)spg(dot)schulergroup(dot)com, pgsql-bugs(at)postgresql(dot)org
Subject: Re: Bug #583: Wrong example in 7.2 Tutorial
Date: 2002-02-12 22:24:53
Message-ID: 200202122224.g1CMOrS00576@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


Great. Patch applied. Thanks.

---------------------------------------------------------------------------

pgsql-bugs(at)postgresql(dot)org wrote:
> Rainer Tammer (rainer(dot)tammer(at)spg(dot)schulergroup(dot)com) reports a bug with a severity of 4
> The lower the number the more severe it is.
>
> Short Description
> Wrong example in 7.2 Tutorial
>
> Long Description
> Wrong referentical integrity example in PostgreSQL 7.2 Tutorial
>
> Sample Code
> Chapter 3.3. Foreign Keys
> =========================
>
> test=# CREATE TABLE cities (
> test(# name varchar(80) primary key,
> test(# location point
> test(# );
> NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'cities_pkey' for table 'cities'
> CREATE
> test=# CREATE TABLE weather (
> test(# city varchar(80) references weather,
> test(# temp_lo int,
> test(# temp_hi int,
> test(# prcp real,
> test(# date date
> test(# );
> NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
> ERROR: PRIMARY KEY for referenced table "weather" not found
>
> I think the following is correct:
>
> CREATE TABLE cities (
> city varchar(80) primary key,
> location point
> );
>
> CREATE TABLE weather (
> city varchar(80) references cities,
> temp_lo int,
> temp_hi int,
> prcp real,
> date date
> );
>
> test=# \d cities
> Table "cities"
> Column | Type | Modifiers
> ----------+-----------------------+-----------
> city | character varying(80) | not null
> location | point |
> Primary key: cities_pkey
> Triggers: RI_ConstraintTrigger_185133,
> RI_ConstraintTrigger_185135
>
> test=# \d weather
> Table "weather"
> Column | Type | Modifiers
> ---------+-----------------------+-----------
> city | character varying(80) |
> temp_lo | integer |
> temp_hi | integer |
> prcp | real |
> date | date |
> Triggers: RI_ConstraintTrigger_185131
>
> test=# INSERT INTO weather VALUES ('Berkeley', 45, 53, 0.0, '1994-11-28');
> ERROR: <unnamed> referential integrity violation - key referenced from weather not found in cities
>
> INSERT INTO cities VALUES ('Berkeley', '0,0');
> INSERT 185138 1
> INSERT INTO weather VALUES ('Berkeley', 45, 53, 0.0, '1994-11-28');
> INSERT 185139 1
>
> Bye
> Rainer Tammer
>
>
> No file was uploaded with this report
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

Attachment Content-Type Size
unknown_filename text/plain 808 bytes

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Innes 2002-02-12 22:25:33 Re: [BUGS] Bug #581: Sequence cannot be deleted
Previous Message Tom Lane 2002-02-12 22:17:01 Re: [BUGS] Bug #581: Sequence cannot be deleted