When I go to


It returns an empty array.

When I go to


It returns all my objects, including 02138.

When I go to


It returns saratoga!

Here is my code:

"""Search for places that match query."""
if not request.args.get("q"):
    raise RuntimeError("Specify location")
q = request.args.get("q") + "%"
place = db.execute("SELECT * FROM places WHERE postal_code LIKE :q OR place_name LIKE :q OR admin_name1 LIKE :q", q=q)
return jsonify(place[1:8])




Remember the array is 0 indexed. When it "searches" for '02138', the query returns 1 row, which is place[0]. Therefore it is not included in return jsonify(place[1:8]) (because place[1:8] is the 2nd through 9th elements of the list and place[0] is not included).

  • Why would it show up if you type in a city name then? – Ianardo Apr 13 '17 at 20:11
  • It is always missing the first row returned from the query, because you are not sending the first row returned from the query to jsonify. Execute the sql in sqlite or phpliteadmin and compare the results to your search request. – DinoCoderSaurus Apr 13 '17 at 21:44
  • SELECT * FROM places WHERE postal_code = 95014 gives me the correct row. – Ianardo Apr 13 '17 at 22:13
  • I'm sure it does. It just doesn't send it to the jsonify call because it is in place[0] in your code. Try place_name = 'Saratoga'. It might be easier to evaluate the difference between what sql returns and what ?search= returns. – DinoCoderSaurus Apr 13 '17 at 22:23
  • So you are saying place should be place[0]? – Ianardo Apr 13 '17 at 22:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .