SQLite - WHERE Clause & UDFs

前端 未结 4 1470
小鲜肉
小鲜肉 2021-01-25 06:18

Intro

I have the following SQLite table with 198,305 geocoded portuguese postal codes:

CREATE TABLE "pt_postal" (
  "code" text NOT N         


        
4条回答
  •  一整个雨季
    2021-01-25 06:19

    Basically, I was using sprintf() to see what kind of bounding coordinates where being computed, and since I couldn't run the query on any place other than PHP (because of the UDF) I was generating another query with prepared statements. The problem was, I wasn't generating the last bound parameter (the kilometers in the distance <= ? clause) and I was fooled by my sprintf() version.

    Guess I shouldn't try to code when I'm sleepy. I'm truly sorry for your wasted time, and thank you all!


    Just for the sake of completeness, the following returns (correctly!) 873 records, in ~ 0.04 seconds:

    SELECT "code",
        geo(38.73311, -9.138707, "geo_latitude", "geo_longitude") AS "distance"
        FROM "pt_postal" WHERE 1 = 1
            AND "geo_latitude" BETWEEN 38.7241268076 AND 38.7420931924
            AND "geo_longitude" BETWEEN -9.15022289523 AND -9.12719110477
            AND "distance" <= 1
        ORDER BY "distance" ASC
    LIMIT 2048;
    

提交回复
热议问题