replacing arcpy script with postgis script