Take the tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am new to this node.js and postgres database. I have done everything perfect querying and getting result. My problem is that when I am running select query in pgAdmin I am getting some 100 rows as output..

My code:

app.get('/reconcile', function(req, res){

var villagename = req.query.query;
var village=name.substring(0,4);
console.log("sub="+village);
console.log("select * from xxxxxxxxx where level4 ILIKE '%"+village+"%'")
   var  query = client.query("select * from tn_village where level4 ILIKE '%"+village+"%'");
   query.on('row', function(rows) {  
   res.send(rows);
});
});

What i want to achieve is .Suppose consider i am searching for "Apple" i am getting words matching "APP" form database by using above(Like) command..Now its showing json as alphabetical order..I want to display json as highest to lowest matching data in Json..

Help me to achieve this..Thanks in advance..

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

query.on('row', …) executes the callback for every row. Use

client.query('…', function(err, result) {
  done();
  res.send(result);
});
share|improve this answer
 
Thanks @ckruse..Its working..But i am facing other problem.. 1)Its returning json for all rows and also printing fields and parsers..I don't want that..I have to display only the rows.. 2)Also How can i remove the files with null value.. –  Subburaj 21 hours ago
 
+1 for your valuable time.. –  Subburaj 19 hours ago
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.