Exemplo n.º 1
0
    def visit_FuncCall(self, node):
        self.write(common.qname(*node.name))

        self.write('(')
        if node.agg_distinct:
            self.write('DISTINCT ')
        self.visit_list(node.args, newlines=False)

        if node.agg_order:
            self.write(' ORDER BY ')
            self.visit_list(node.agg_order, newlines=False)

        self.write(')')

        if node.agg_filter:
            self.write(' FILTER (WHERE ')
            self.visit(node.agg_filter)
            self.write(')')

        if node.over:
            self.write(' OVER (')
            if node.over.partition_clause:
                self.write('PARTITION BY ')
                self.visit_list(node.over.partition_clause, newlines=False)

            if node.over.order_clause:
                self.write(' ORDER BY ')
                self.visit_list(node.over.order_clause, newlines=False)

            # XXX: add support for frame definition

            self.write(')')

        if node.with_ordinality:
            self.write(' WITH ORDINALITY')
Exemplo n.º 2
0
    def visit_FuncCall(self, node):
        self.write(common.qname(*node.name))

        self.write('(')
        if node.agg_distinct:
            self.write('DISTINCT ')
        self.visit_list(node.args, newlines=False)

        if node.agg_order:
            self.write(' ORDER BY ')
            self.visit_list(node.agg_order, newlines=False)

        self.write(')')

        if node.agg_filter:
            self.write(' FILTER (WHERE ')
            self.visit(node.agg_filter)
            self.write(')')

        if node.over:
            self.write(' OVER (')
            if node.over.partition_clause:
                self.write('PARTITION BY ')
                self.visit_list(node.over.partition_clause, newlines=False)

            if node.over.order_clause:
                self.write(' ORDER BY ')
                self.visit_list(node.over.order_clause, newlines=False)

            # XXX: add support for frame definition

            self.write(')')

        if node.with_ordinality:
            self.write(' WITH ORDINALITY')
Exemplo n.º 3
0
 def visit_TypeName(self, node):
     self.write(common.qname(*node.name))
     if node.array_bounds:
         for array_bound in node.array_bounds:
             self.write('[')
             if array_bound >= 0:
                 self.write(array_bound)
             self.write(']')
Exemplo n.º 4
0
 def visit_ColumnRef(self, node):
     names = node.name
     if isinstance(names[-1], pgast.Star):
         self.write(common.qname(*names[:-1]))
         if len(names) > 1:
             self.write('.')
         self.write('*')
     else:
         if names == ['VALUE']:
             self.write(names[0])
         elif names[0] in {'OLD', 'NEW'}:
             self.write(names[0])
             if len(names) > 1:
                 self.write('.')
                 self.write(common.qname(*names[1:]))
         else:
             self.write(common.qname(*names))
Exemplo n.º 5
0
 def visit_TypeName(self, node):
     self.write(common.qname(*node.name))
     if node.array_bounds:
         for array_bound in node.array_bounds:
             self.write('[')
             if array_bound >= 0:
                 self.write(array_bound)
             self.write(']')
Exemplo n.º 6
0
 def visit_ColumnRef(self, node):
     names = node.name
     if isinstance(names[-1], pgast.Star):
         self.write(common.qname(*names[:-1]))
         if len(names) > 1:
             self.write('.')
         self.write('*')
     else:
         if names == ['VALUE']:
             self.write(names[0])
         elif names[0] in {'OLD', 'NEW'}:
             self.write(names[0])
             if len(names) > 1:
                 self.write('.')
                 self.write(common.qname(*names[1:]))
         else:
             self.write(common.qname(*names))
Exemplo n.º 7
0
    async def creation_code(self, context):
        link_map = await context.get_class_map()

        ids = tuple(sorted(list(link_map[n] for n in self.link_names)))
        id_str = '_'.join(str(i) for i in ids)

        name = '%s_%s_%s_cardinality_idx' % (self.name_prefix, id_str,
                                             self.cardinality)
        name = common.edgedb_name_to_pg_name(name)
        predicate = 'ptr_item_id IN (%s)' % ', '.join(str(id) for id in ids)

        code = '''
            CREATE {unique} INDEX {name} ON {table}s ({cols}) {predicate}
        '''.format(unique='UNIQUE',
                   name=common.qname(name),
                   table=common.qname(*self.table_name),
                   cols=', '.join(common.quote_ident(c) for c in self.columns),
                   predicate=('WHERE {}'.format(predicate)))

        return code
Exemplo n.º 8
0
    async def creation_code(self, context):
        link_map = await context.get_class_map()

        ids = tuple(sorted(list(link_map[n] for n in self.link_names)))
        id_str = '_'.join(str(i) for i in ids)

        name = '%s_%s_%s_cardinality_idx' % (
            self.name_prefix, id_str, self.cardinality)
        name = common.edgedb_name_to_pg_name(name)
        predicate = 'ptr_item_id IN (%s)' % ', '.join(str(id) for id in ids)

        code = '''
            CREATE {unique} INDEX {name} ON {table}s ({cols}) {predicate}
        '''.format(unique='UNIQUE',
                   name=common.qname(name),
                   table=common.qname(*self.table_name),
                   cols=', '.join(common.quote_ident(c) for c in self.columns),
                   predicate=('WHERE {}'.format(predicate)))

        return code
Exemplo n.º 9
0
 def visit_Relation(self, node):
     if node.schemaname is None:
         self.write(common.qname(node.name))
     else:
         self.write(common.qname(node.schemaname, node.name))
Exemplo n.º 10
0
 def visit_Relation(self, node):
     if node.schemaname is None:
         self.write(common.qname(node.name))
     else:
         self.write(common.qname(node.schemaname, node.name))