couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Wolff <awo...@gmail.com>
Subject Re: CouchDB equivalent dynamic SQL
Date Fri, 30 Oct 2009 23:23:53 GMT
You can make two queries
?startkey= [ "computer", 1000]&endkey=["computer" , 2000]
?startkey= ["tv", 1000]&endkey=["tv" , 2000]

If couch had multi-range queries(
https://issues.apache.org/jira/browse/COUCHDB-523), you could do this in one
request.

alternatively, depending on the shape of your data, you could just index
everything by price and filter types in your application. my understanding
is that this is what a SQL db would do on the server-side.

A

On Fri, Oct 30, 2009 at 1:46 PM, Duy Nguyen <duynguyen0511@yahoo.com> wrote:

> Thanks for reply , guys. If i want to select all tv or computer that have
> price in between 1000 and 2000,
> ?startkey= [ ["computer", "tv"] , 1000]&endkey=[["computer", "tv"] ,
> 2000]&include_docs=true
> Is it correct ?
>
> --- On Sat, 10/31/09, Adam Kocoloski <kocolosk@apache.org> wrote:
>
> From: Adam Kocoloski <kocolosk@apache.org>
> Subject: Re: CouchDB equivalent dynamic SQL
> To: user@couchdb.apache.org
> Date: Saturday, October 31, 2009, 12:59 AM
>
> 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
>
>
>
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message