Some queries have different syntax depending what version of postgres
        we are querying against.

        :returns: boolean
541431
def is_pg_at_least_nine_two(self):
        

        if self._is_pg_at_least_nine_two is None:
            results = self.version()
            regex = re.compile("PostgreSQL (\d+\.\d+\.\d+) on")
            matches = regex.match(results[0].version)
            version = matches.groups()[0]

            if version > '9.2.0':
                self._is_pg_at_least_nine_two = True
            else:
                self._is_pg_at_least_nine_two = False

        return self._is_pg_at_least_nine_two
410212
def find(self, query):
        ''''''
        if self.upstream:
            return self.upstream.find(query)
        else:
            return False
337673
def check_version(version):
    

    if isinstance(version, string_types):
        version = tuple(map(int, version.split(".")))

    if version > version_info:
        str_version = ".".join(map(str, version))
        raise ValueError("pgi version '%s' requested, '%s' available" %
                         (str_version, __version__))
335152
def is_sqlatype_date(coltype: TypeEngine) -> bool:
    
    coltype = _coltype_to_typeengine(coltype)
    # No longer valid in SQLAlchemy 1.2.11:
    # return isinstance(coltype, sqltypes._DateAffinity)
    return (
        isinstance(coltype, sqltypes.DateTime) or
        isinstance(coltype, sqltypes.Date)
    )
594844
def is_processed(self, db_versions):
        
        return self.number in (v.number for v in db_versions if v.date_done)
599241
def check_rules(self):
        
        query = """
        select n.nspname as rule_schema,
        c.relname as rule_table,
        case r.ev_type
            when '1' then 'SELECT'
            when '2' then 'UPDATE'
            when '3' then 'INSERT'
            when '4' then 'DELETE'
            else 'UNKNOWN'
        end as rule_event
        from pg_rewrite r
        join pg_class c on r.ev_class = c.oid
        left join pg_namespace n on n.oid = c.relnamespace
        left join pg_description d on r.oid = d.objoid
        WHERE n.nspname NOT IN {excl}
            AND r.rulename != '_RETURN'
            AND n.nspname NOT LIKE 'pg\_%'
        ORDER BY n.nspname, c.relname, rule_event
        """.format(excl=self.exclude_schema)

        return self.__check_equals(query)
27752
def isNewerThan(self, other):
        
        if self.getValue("name") == other.getValue("name"):
            if other.getValue("version"):
                if not other.getValue("version"):
                    return False
                else:
                    return LooseVersion(self.getValue("version")) > LooseVersion(other.getValue("version"))
            else:
                return True
        else:
            return False
364923
def check_query(query):
    
    q = query.lower()
    if "select " not in q:
        raise InvalidQuery("SELECT word not found in the query: {0}".format(query))
    if " from " not in q:
        raise InvalidQuery("FROM word not found in the query: {0}".format(query))
273929
def query(self):
        
        tree = pypeg2.parse(self._query, parser(), whitespace="")
        for walker in query_walkers():
            tree = tree.accept(walker)
        return tree
357304
def __get_dbms_version(self, make_connection=True):
        
        if not self.connection and make_connection:
            self.connect()
        with self.connection.cursor() as cursor:
            cursor.execute("SELECT SERVERPROPERTY('productversion')")
            return cursor.fetchone()[0]
610809
def _validate_version(connection, dsn):
    
    try:
        version = get_stored_version(connection)
    except VersionIsNotStored:
        logger.debug('Version not stored in the db: assuming new database creation.')
        version = SCHEMA_VERSION
        _update_version(connection, version)
    assert isinstance(version, int)

    if version > 10 and version < 100:
        raise DatabaseError('You are trying to open an old SQLite database.')

    if _migration_required(connection):
        migrate(connection, dsn)
718382
def compile_select(self, query):
        
        sql = super(MySqlQueryGrammar, self).compile_select(query)

        if query.unions:
            sql = '(%s) %s' % (sql, self._compile_unions(query))

        return sql
461541
def extract_queries(self, args, kwargs):
        '''
            
        '''
        return super(POSTGRESExtPillar, self).extract_queries(args, kwargs)
1006006
def query(self):
        
        if self._rawquery==True:
            return self.__query
        return flatten(self.__query)
64245
def _get_db_version(self):
        

        dbname = self._cfg.get('nipapd', 'db_name')
        self._execute("SELECT description FROM pg_shdescription JOIN pg_database ON objoid = pg_database.oid WHERE datname = '%s'" % dbname)
        comment = self._curs_pg.fetchone()
        if comment is None:
            raise NipapDatabaseNoVersionError("Could not find comment of psql database %s" % dbname)

        db_version = None
        m = re.match('NIPAP database - schema version: ([0-9]+)', comment[0])
        if m:
            db_version = int(m.group(1))
        else:
            raise NipapError("Could not match schema version database comment")

        return db_version
235274
def _check_query(self, query, style_cols=None):
        """"""
        try:
            self.sql_client.send(
                utils.minify_sql((
                    'EXPLAIN',
                    'SELECT',
                    '  {style_cols}{comma}',
                    '  the_geom, the_geom_webmercator',
                    'FROM ({query}) _wrap;',
                )).format(query=query,
                          comma=',' if style_cols else '',
                          style_cols=(','.join(style_cols)
                                      if style_cols else '')),
                do_post=False)
        except Exception as err:
            raise ValueError(('Layer query `{query}` and/or style column(s) '
                              '{cols} are not valid: {err}.'
                              '').format(query=query,
                                         cols=', '.join(['`{}`'.format(c)
                                                         for c in style_cols]),
                                         err=err))
1309405
def check_native_jsonfield_postgres_engine(app_configs=None, **kwargs):
	
	from . import settings as djstripe_settings

	messages = []
	error_msg = "DJSTRIPE_USE_NATIVE_JSONFIELD is not compatible with engine {engine} for database {name}"

	if djstripe_settings.USE_NATIVE_JSONFIELD:
		for db_name, db_config in settings.DATABASES.items():
			# Hi there.
			# You may be reading this because you are using Postgres, but
			# dj-stripe is not detecting that correctly. For example, maybe you
			# are using multiple databases with different engines, or you have
			# your own backend. As long as you are certain you can support jsonb,
			# you can use the SILENCED_SYSTEM_CHECKS setting to ignore this check.
			engine = db_config.get("ENGINE", "")
			if "postgresql" not in engine and "postgis" not in engine:
				messages.append(
					checks.Critical(
						error_msg.format(name=repr(db_name), engine=repr(engine)),
						hint="Switch to Postgres, or unset DJSTRIPE_USE_NATIVE_JSONFIELD",
						id="djstripe.C005",
					)
				)

	return messages