@@ -55,7 +55,8 @@ def __init__(self, iface, db, parent=None):
55
55
self .iface = iface
56
56
self .db = db
57
57
self .filter = ""
58
- self .allowMultiColumnPk = isinstance (db , PGDatabase ) # at the moment only PostGIS allows a primary key to span multiple columns, spatialite doesn't
58
+ self .allowMultiColumnPk = isinstance (db , PGDatabase ) # at the moment only PostgreSQL allows a primary key to span multiple columns, spatialite doesn't
59
+ self .aliasSubQuery = isinstance (db , PGDatabase ) # only PostgreSQL requires subqueries to be aliases
59
60
self .setupUi (self )
60
61
self .setWindowTitle (
61
62
u"%s - %s [%s]" % (self .windowTitle (), db .connection ().connectionName (), db .connection ().typeNameString ()))
@@ -283,15 +284,6 @@ def fillColumnCombos(self):
283
284
284
285
QApplication .setOverrideCursor (QCursor (Qt .WaitCursor ))
285
286
286
- # get a new alias
287
- aliasIndex = 0
288
- while True :
289
- alias = "_%s__%d" % ("subQuery" , aliasIndex )
290
- escaped = re .compile ('\\ b("?)' + re .escape (alias ) + '\\ 1\\ b' )
291
- if not escaped .search (query ):
292
- break
293
- aliasIndex += 1
294
-
295
287
# remove a trailing ';' from query if present
296
288
if query .strip ().endswith (';' ):
297
289
query = query .strip ()[:- 1 ]
@@ -300,7 +292,19 @@ def fillColumnCombos(self):
300
292
cols = []
301
293
quotedCols = []
302
294
connector = self .db .connector
303
- sql = u"SELECT * FROM (%s\n ) AS %s WHERE 0=1" % (unicode (query ), connector .quoteId (alias ))
295
+ if self .aliasSubQuery :
296
+ # get a new alias
297
+ aliasIndex = 0
298
+ while True :
299
+ alias = "_subQuery__%d" % aliasIndex
300
+ escaped = re .compile ('\\ b("?)' + re .escape (alias ) + '\\ 1\\ b' )
301
+ if not escaped .search (query ):
302
+ break
303
+ aliasIndex += 1
304
+
305
+ sql = u"SELECT * FROM (%s\n ) AS %s LIMIT 0" % (unicode (query ), connector .quoteId (alias ))
306
+ else :
307
+ sql = u"SELECT * FROM (%s\n ) WHERE 1=0" % unicode (query )
304
308
305
309
c = None
306
310
try :
0 commit comments