Pergunta

I'm writing a Couchdb _design document for the SQL command below:

SELECT NVL(MAX(NVL(VERSION,0)),0)+1 FROM pricelistdocs WHERE 
PRICE_LIST_ID = ?  AND DELETION_FLAG = 0;

I came up with a _design view function below while run and return values but I doubt if the correct and fulfills expectation of the above SQL command.

function(doc){
 if(doc.PRICE_LIST_ID == "110011"  && doc.DELETION_FLAG == "0" ){
   emit(doc._id, doc.VERSION);
 }
}

Please how can I add the NVL() and MAX function to my _design view document above. Any infortiom or clue is appreciated. Thank you for your time.

Foi útil?

Solução

You can write your own NVL function by checking for the existance of a field and returning 0 if it does not exist.

For the max functionality, you have to add a reduce function to your view. If you just want to get the maximum, "reduce": "_max" will do, which is a built in reduce function.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top