Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 04E4BB5DBD6 for ; Thu, 15 Sep 2011 08:42:59 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 32995-09 for ; Thu, 15 Sep 2011 11:42:48 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from mail-qy0-f181.google.com (mail-qy0-f181.google.com [209.85.216.181]) by mail.postgresql.org (Postfix) with ESMTP id 3A5B3B5DBCB for ; Thu, 15 Sep 2011 08:42:48 -0300 (ADT) Received: by qyk7 with SMTP id 7so2869876qyk.19 for ; Thu, 15 Sep 2011 04:42:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=8RgWm5CKtye7ZCL3BnCAp+xy2xcu6kWMNERkTzL8u5Y=; b=HTDLMuGlSmbg1OtMnYwHfUfhi/A2uUGg/qeUwzhU41Pys1NDzd0Vs5eQJ8b+ouOhar BqlCgtzMMWPsMz9s5BriJuIH7+TilgOjJDtZyBW15GrOwGtQ5zXaTDhvyHjX6TKXWDdI 6FLlsfZ9BginmCaI4b0CL7aiomSbH1cyhOgOk= MIME-Version: 1.0 Received: by 10.229.66.31 with SMTP id l31mr796766qci.201.1316086968009; Thu, 15 Sep 2011 04:42:48 -0700 (PDT) Received: by 10.229.236.71 with HTTP; Thu, 15 Sep 2011 04:42:47 -0700 (PDT) In-Reply-To: <201109120209.p8C29kF13404@momjian.us> References: <201109120209.p8C29kF13404@momjian.us> Date: Thu, 15 Sep 2011 06:42:47 -0500 Message-ID: Subject: Re: 5.3.5. Foreign Keys (The SQL Language) possible enhance From: Robert Haas To: Bruce Momjian Cc: Grzegorz Szpetkowski , pgsql-docs@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.899 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001 X-Spam-Level: X-Archive-Number: 201109/47 X-Sequence-Number: 6968 On Sun, Sep 11, 2011 at 9:09 PM, Bruce Momjian wrote: > Robert Haas wrote: >> On Fri, May 6, 2011 at 9:50 PM, Grzegorz Szpetkowski >> wrote: >> > I have some remark about >> > >> > "Now it is impossible to create orders with product_no entries that do >> > not appear in the products table." >> > >> > http://www.postgresql.org/docs/9.0/static/ddl-constraints.html#DDL-CONSTRAINTS-FK >> [...] >> > >> > There is still possibility to add product_no (exactly NULL) value, >> > which does not appear (cannot because of primary key nature) in >> > products table. To get "full solution" you need create orders table as >> > >> > CREATE TABLE orders ( >> > ? ?order_id integer PRIMARY KEY, >> > ? ?product_no integer REFERENCES products (product_no) NOT NULL, >> > ? ?quantity integer >> > ); >> >> I don't think we should change the example, but we could probably >> clarify the wording. > > Any ideas on how to clarify the wording? Maybe something like this: Now every product_no that appears in the orders table must also appear in the products table. Foreign key constraints are not checked for NULL values, so product_no may also be NULL; we could prohibit this by declaring the column NOT NULL. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company