Does anyone know of an equivalent to ArcPy’s search cursor in PostgreSQL?
I’ve moved from using Arc to PostGIS/QGIS for the first time and have a task that would have been perfect for search cursor but have no idea if there is/what the equivalent would be. If anyone knows postgreSQL equivalents for update cursor too that would be a huge help too as I’m sure I’ll find I’m missing using that too soon.
Hi,
Reviewing the Search Cursor syntax:
SearchCursor (dataset, {where_clause}, {spatial_reference}, {fields}, {sort_fields})
https://pro.arcgis.com/en/pro-app/arcpy/functions/searchcursor.htm
It sounds like what you’re asking is really how to compose an SQL SELECT statement using PostGIS. If that’s the case and if you haven’t already done so, I’d suggest you review the excellent SQL examples in the PostGIS documentation:
8. Simple SQL Exercises — Introduction to PostGIS
And of course the postgres documentation describing the SELECT statement in detail:
SELECT
- Hi soumyarani,
Since PostgreSQL is a database system, with full fledged standard SQL support with Procedural language support. you can consider mainly 2 things.
SQL’s Common Table Expressions (CTE). Which will allow you to hold query results and use them in the subsequent quries for further processing. CTEs are part of SQL syntax.
The cursors offered by plpgsql language. which is the default language offered by PostgreSQL , Please refer : https://www.postgresql.org/docs/current/plpgsql-cursors.html
- for more details. You may use other languages including Python using PL/Python extension.
Hope this helps
Jobin.