Index: ogrsf_frmts/pg/ogrpgresultlayer.cpp
===================================================================
--- ogrsf_frmts/pg/ogrpgresultlayer.cpp	(revision 24191)
+++ ogrsf_frmts/pg/ogrpgresultlayer.cpp	(working copy)
@@ -59,27 +59,35 @@
     /* to do spatial filtering */
     if (bHasPostGISGeometry)
     {
-        CPLString osGetSRID;
-        osGetSRID += "SELECT getsrid(";
-        osGetSRID += OGRPGEscapeColumnName(pszGeomColumn);
-        osGetSRID += ") FROM (";
-        osGetSRID += pszRawStatement;
-        osGetSRID += ") AS ogrpggetsrid LIMIT 1";
+        const char* sridOption = CPLGetConfigOption( "PGSQL_SRID", NULL );
+        if( sridOption == NULL )
+        {
+            CPLString osGetSRID;
+            osGetSRID += "SELECT getsrid(";
+            osGetSRID += OGRPGEscapeColumnName(pszGeomColumn);
+            osGetSRID += ") FROM (";
+            osGetSRID += pszRawStatement;
+            osGetSRID += ") AS ogrpggetsrid LIMIT 1";
 
-        PGresult* hSRSIdResult = OGRPG_PQexec(poDS->GetPGConn(), osGetSRID );
+            PGresult* hSRSIdResult = OGRPG_PQexec(poDS->GetPGConn(), osGetSRID );
 
-        if( hSRSIdResult && PQresultStatus(hSRSIdResult) == PGRES_TUPLES_OK)
-        {
-            if ( PQntuples(hSRSIdResult) > 0 )
-                nSRSId = atoi(PQgetvalue(hSRSIdResult, 0, 0));
+            if( hSRSIdResult && PQresultStatus(hSRSIdResult) == PGRES_TUPLES_OK)
+            {
+                if ( PQntuples(hSRSIdResult) > 0 )
+                    nSRSId = atoi(PQgetvalue(hSRSIdResult, 0, 0));
+            }
+            else
+            {
+                CPLError( CE_Failure, CPLE_AppDefined,
+                            "%s", PQerrorMessage(poDS->GetPGConn()) );
+            }
+
+            OGRPGClearResult(hSRSIdResult);            
         }
         else
         {
-            CPLError( CE_Failure, CPLE_AppDefined,
-                        "%s", PQerrorMessage(poDS->GetPGConn()) );
+            nSRSId = atoi( sridOption );
         }
-
-        OGRPGClearResult(hSRSIdResult);
     }
     else if (bHasPostGISGeography)
     {
