MCPcopy
hub / github.com/geldata/gel / visit_SelectStmt

Method visit_SelectStmt

edb/pgsql/codegen.py:272–433  ·  view source on GitHub ↗
(self, node: pgast.SelectStmt)

Source from the content-addressed store, hash-verified

270 self.write(')')
271
272 def visit_SelectStmt(self, node: pgast.SelectStmt) -> None:
273 parenthesize = not self.is_toplevel
274
275 if parenthesize:
276 if not self.reordered and self.result:
277 self.new_lines = 1
278 self.write('(')
279 if self.reordered:
280 self.new_lines = 1
281 if not node.op:
282 self.indentation += 1
283
284 if node.ctes:
285 self.write('WITH ')
286 self.gen_ctes(node.ctes)
287
288 if node.values:
289 self.write('VALUES')
290 self.new_lines = 1
291 self.visit_list(node.values)
292 if parenthesize:
293 self.new_lines = 1
294 if self.reordered and not node.op:
295 self.indentation -= 1
296 self.write(')')
297 return
298
299 # If reordered is True, we try to put the FROM clause *before* SELECT,
300 # like it *ought* to be. We do various hokey things to try to make
301 # that look good.
302 # Otherwise we emit real SQL.
303 def _select() -> None:
304 self.write('SELECT')
305 if node.distinct_clause:
306 self.write(' DISTINCT')
307 if len(node.distinct_clause) > 1 or not isinstance(
308 node.distinct_clause[0], pgast.Star
309 ):
310 self.write(' ON (')
311 self.visit_list(node.distinct_clause, newlines=False)
312 self.write(')')
313 if self.pretty:
314 self.write('/*', repr(node), '*/')
315 self.new_lines = 1
316
317 if node.op:
318 # Upper level set operation node (UNION/INTERSECT)
319
320 # HACK: The LHS of a set operation is *not* top-level, and
321 # shouldn't be treated as such. Since we (also hackily)
322 # use whether anything has been written do determine
323 # whether we are at the top level, write out an empty
324 # string to force parenthesization.
325 self.is_toplevel = False
326 self.visit(node.larg)
327 self.write(' ' + node.op + ' ')
328 if node.all:
329 self.write('ALL ')

Callers

nothing calls this directly

Calls 5

writeMethod · 0.95
gen_ctesMethod · 0.95
visitMethod · 0.95
_selectFunction · 0.85
visit_listMethod · 0.80

Tested by

no test coverage detected