1

I've been banging my head against this for a while, and am seeking some insight into what I'm doing wrong. I have the following snippet of code:

params = [PlaneRep.hex, PlaneRep.squawk, PlaneRep.flight, PlaneRep.isMetric, 
    PlaneRep.mlat, PlaneRep.altitude, PlaneRep.speed, PlaneRep.vert_rate,
    dbdate, dbtime, PlaneRep.track, coordinates, PlaneRep.messages]
sql = '''
    INSERT into planereports (hex, squawk, flight, "isMetric", "isMLAT", altitude, speed, vert_rate, date_of_report, time_of_report, bearing, report_location, messages_sent)
    VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, ST_PointFromText(%s, 4326), %s);'''
print(cur.mogrify(sql, params))
cur.execute(sql,params)

which yields the following error:

b'\n\t\tINSERT into planereports (hex, squawk, flight, "isMetric",     "isMLAT", altitude, speed, vert_rate, date_of_report, time_of_report,     bearing, report_location, messages_sent)\n\t\tVALUES (\'7c6d33\', \'3241\',     \'VOZ850  \', true, false, 9563, 822, 546.2016, \'2015-10-21\', \'04:32:41\', 235, ST_PointFromText(\'POINT(150.464266 -34.754929)\', 4326), 133);'
Traceback (most recent call last)
File "./jsonfiddling.py", line 92, in <module>
logToDB(dbconn, plane) 
File "./jsonfiddling.py", line 34, in logToDB
 cur.execute(sql,params)
 psycopg2.ProgrammingError: function st_pointfromtext(unknown, integer)    does not exist
LINE 3: ...63, 822, 546.2016, '2015-10-21', '04:32:41', 235, ST_PointFr...
                                                         ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

Any ideas of what I'm doing wrong?

1

It looks like your PostGIS is not being detected.

Can you verify you can do:

SELECT postgis_full_version();

If you used geodjango or ruby (ruby I know for sure is a case), they install PostGIS in a schema called "postgis" instead of public, so if that's the case, you may need to add that to your database search_path and also make sure the account you are connecting with has access to that schema.

ALTER DATABASE mydb SET search_path="$user",public,postgis;
GRANT ALL ON SCHEMA postgis TO public;
  • postgres=# SELECT postgis_full_version(); Looks like you're right - ERROR: function postgis_full_version() does not exist LINE 1: SELECT postgis_full_version(); ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. – shocking Oct 21 '15 at 5:11
  • I'm using fedora22, and postgis is definitely installed. I had to create the postgis extension on that database for it to work - now I have a completely separate problem, but that's for another day.... – shocking Oct 21 '15 at 5:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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