Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id EAB9B633E99 for ; Mon, 13 Apr 2009 18:09:51 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 25589-01 for ; Mon, 13 Apr 2009 18:09:50 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qy0-f115.google.com (mail-qy0-f115.google.com [209.85.221.115]) by mail.postgresql.org (Postfix) with ESMTP id 50EAF6329A4 for ; Mon, 13 Apr 2009 18:09:50 -0300 (ADT) Received: by qyk13 with SMTP id 13so3885828qyk.15 for ; Mon, 13 Apr 2009 14:09:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=goSMkP+ZuKcXkA1pka6z50/kllUrfSnewPX1WT5Y9MA=; b=UrbwFlk9bEylwzDejmR6WTHeJl49A8h4Nb92Icx37Pc5kPTCoO7HFZ7Oc5ivEJA5EQ oNgA9gXLuTvJq0dgR+7q8Qwgx9tXmA2nTLEiPIDQeswRACSc4++8dX2AWNhqcG+3TVX7 YHw5heN8zq9dytN/3gxSgVuSZzGtUMI82dkkM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=t/zHYnwfyKFnVXRTDDWIR8WcVbXbzZpcMgvjjNw7tfKSl978iNyT6DjeLWPENe8KD4 X0utmmKnXQfOeCROFEThvEUfdQsPrceeRoEBOFenY5cw6O7A7Kn1fEQvnBz+EAAe3jV3 /9Jv3EBoas5keiYmerNERE7sDqR2S+7pJr4Uo= MIME-Version: 1.0 Received: by 10.229.96.13 with SMTP id f13mr1784082qcn.36.1239656989253; Mon, 13 Apr 2009 14:09:49 -0700 (PDT) In-Reply-To: <49E37441.6030301@frii.com> References: <49DC1034.1060705@frii.com> <49E37441.6030301@frii.com> Date: Mon, 13 Apr 2009 17:09:49 -0400 Message-ID: Subject: Re: changing multiple pk's in one update From: Glenn Maynard To: pgsql-sql@postgresql.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200904/62 X-Sequence-Number: 32408 (JMdict? I was playing with importing that into a DB a while back, but the attributes in that XML are such a pain--and then my email died while I was trying to get those changed, and I never picked it up again.) On Mon, Apr 13, 2009 at 1:20 PM, Stuart McGraw wrote: > 1 to the number of sentences in the entry) and the sentence text. =C2=A0T= he pk is > of course the entry id and the sense number. > There are other tables that have fk's to the senses. Your PK is a composite of (entry, order)? Won't your foreign keys elsewhere all break when you shift the order around? > I guess I could add an "order"[1] column and use the sense number as a > surrogate partial key to avoid the need for key renumbering, > but all the api's (and the normal human way of thinking) are based > on "sense number 1 of entry x", "sense number 2 of entry y", so > one would need to maintain "order" as a gapless sequence (or add a new > mapping layer to map from/to a arbitrary monotonic sequence > to a 1,2,3,... sequence) -- the gain doesn't seem that big. Why not do this in the straightforward way: three separate fields: a regular, sequential PK; an FK to the entry; and an order number. Add an index on (entry_key, order_number). It's a little more expensive since you have a new column and index (the PK), but in a table with a lot of plain text that's probably insignificant. Now you can use the plain PK for your FK's. I'd anticipate other problems with changing your PKs. If you're referring to sense (100,3), and a concurrent user adds a sense, you may suddenly find yourself referring to a different sense due to them being reordered out from under you. You'd have similar problems if your sense is deleted entirely: instead of the row simply ceasing to exist (and resulting in predictable, checkable errors), you may end up silently referring to another sense. Maybe I'm misunderstanding what you're doing, though. You'd have to have no UNIQUE constraint on the (entry, order) composite index, though, or you'll have the same problem when you reorder them. --=20 Glenn Maynard