'Returns a CQL query that can be used to recreate this function.
If `formatted` is set to :const:`True`, extra whitespace will
be added to make the query more readable.'

def as_cql_query(self, formatted=False):

    sep = ('\n                ' if formatted else '    ')
    keyspace = protect_name(self.keyspace)
    name = protect_name(self.name)
    arg_list = ',    '.join([('%s    %s' % (protect_name(n), t)) for (n, t) in zip(self.argument_names, self.argument_types)])
    typ = self.return_type
    lang = self.language
    body = self.body
    on_null = ('CALLED' if self.called_on_null_input else 'RETURNS    NULL')
    return ('CREATE    FUNCTION    %(keyspace)s.%(name)s(%(arg_list)s)%(sep)s%(on_null)s    ON    NULL    INPUT%(sep)sRETURNS    %(typ)s%(sep)sLANGUAGE    %(lang)s%(sep)sAS    $$%(body)s$$' % locals())
