Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 58091 invoked from network); 30 Oct 2009 17:59:55 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 30 Oct 2009 17:59:55 -0000 Received: (qmail 13061 invoked by uid 500); 30 Oct 2009 17:59:54 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 12998 invoked by uid 500); 30 Oct 2009 17:59:54 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 12988 invoked by uid 99); 30 Oct 2009 17:59:54 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Oct 2009 17:59:54 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of adam.kocoloski@gmail.com designates 209.85.219.205 as permitted sender) Received: from [209.85.219.205] (HELO mail-ew0-f205.google.com) (209.85.219.205) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Oct 2009 17:59:45 +0000 Received: by ewy1 with SMTP id 1so3128828ewy.3 for ; Fri, 30 Oct 2009 10:59:25 -0700 (PDT) Received: by 10.216.93.15 with SMTP id k15mr653610wef.103.1256925564958; Fri, 30 Oct 2009 10:59:24 -0700 (PDT) Received: from ?10.0.1.9? (c-71-232-49-44.hsd1.ma.comcast.net [71.232.49.44]) by mx.google.com with ESMTPS id j8sm584216gvb.4.2009.10.30.10.59.23 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 30 Oct 2009 10:59:24 -0700 (PDT) Content-Type: text/plain; charset=us-ascii; format=flowed; delsp=yes Mime-Version: 1.0 (Apple Message framework v1076) Subject: Re: CouchDB equivalent dynamic SQL From: Adam Kocoloski In-Reply-To: <243703.63807.qm@web52207.mail.re2.yahoo.com> Date: Fri, 30 Oct 2009 13:59:21 -0400 Content-Transfer-Encoding: 7bit Message-Id: <415EAAEA-4699-4AA2-8368-E8FF6E305750@apache.org> References: <243703.63807.qm@web52207.mail.re2.yahoo.com> To: user@couchdb.apache.org X-Mailer: Apple Mail (2.1076) X-Virus-Checked: Checked by ClamAV on apache.org On Oct 30, 2009, at 1:36 PM, Duy Nguyen wrote: > Hi guys, > I have a troublesome sql query that needs to translate to couchDB > map/reduce > SELECT * FROM PRODUCTSWHERE [ PRICE ] AND [TYPE]' > Please note that Price and Type are dynamically generated depend on > user inputs. ( i.e TYPEcan be 100 < PRICE < 1000, or 1 < PRICE < > 100, or 1000 < PRICE < 10000. TYPE could be 'computer' , 'tv' etc..) > I can not do dynamically query on the fly with CouchDB. what is the > best way to solve this problem ? Hi Duy, it won't always be a perfect translation. But CouchDB's compound view keys should be able to help you in this situation. In your map, emit([doc.type, doc.price], null) and then query the view with ?startkey=["computer", 1000]&endkey=["computer", 10000] &include_docs=true or ?startkey=["tv", 100]&endkey=["tv", 1000]&include_docs=true Best, Adam