Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 376729FA1FE for ; Fri, 1 Dec 2006 09:50:47 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 92267-03 for ; Fri, 1 Dec 2006 09:50:39 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.229]) by postgresql.org (Postfix) with ESMTP id 6C4EC9FA178 for ; Fri, 1 Dec 2006 09:50:39 -0400 (AST) Received: by wx-out-0506.google.com with SMTP id i28so2949198wxd for ; Fri, 01 Dec 2006 05:50:38 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition:x-google-sender-auth; b=UMfWnqB/1y/wqFTjdsz+bLztvqzvYWDS8s+T5or8ZD09MetQfuH7QGOazxdmRZU/jfjX2EXSaQ3JcsrESCSgg84CZPPXAVru9wdE8uKDCOyjwhZnr3I7zujxk/67oU29/8N+115PGGu4U7TGBKJXPUrf3D5cGzb8Z5V26H7HcJk= Received: by 10.90.52.18 with SMTP id z18mr5035148agz.1164981037806; Fri, 01 Dec 2006 05:50:37 -0800 (PST) Received: by 10.90.65.3 with HTTP; Fri, 1 Dec 2006 05:50:37 -0800 (PST) Message-ID: <9d8bdcf30612010550o3a5721lefc366e4984fd145@mail.gmail.com> Date: Sat, 2 Dec 2006 00:50:37 +1100 From: "Markus Juenemann" To: pgsql-sql@postgresql.org Subject: Setting boolean column based on cumulative integer value MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Google-Sender-Auth: 93438bf3bbde710e X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/4 X-Sequence-Number: 26960 Hi (again!) [stupid email program sent my message before I finished it!!!] I've got a bit of a tricky (for me!) problem. The example below is completely ficticious but describes my real problem in a way which might be easier to understand. Imagine the table contains a list of passenger wanting to get on a small(!) plane. The plane can carry at most 200kg of passengers and will be filled strictly on a first-come first-serve basis - well, check-in staff is a bit stupid ;-). So what needs to be done is to set the 'gets_seat' column to true until the weight limit is reached. CREATE TABLE passenger_queue ( id serial NOT NULL, name character varying(40) NOT NULL, weight integer NOT NULL, gets_seat boolean default false ) insert into passenger_queue values (1,"Peter",75,false) insert into passenger_queue values (2,"Mary",50,false) insert into passenger_queue values (3,"John",70,false) insert into passenger_queue values (4,"Steve",80,false) According to the specifications given above Peter, Mary and John would have 'gets_seat' set to true because their cumulative weight is 195kg while Steve misses out. The big question is: How can I do this in a nice SQL query??? Thanks Markus