Determine if the running engine is postgres
960407
def _is_postgres(self):
        
        if self._is_postgres_engine is None:
            is_postgres_engine = False
            try:
                dialect = self.session.bind.engine.name
                if 'redshift' in dialect or 'postg' in dialect or 'pg' in \
                        dialect:
                    is_postgres_engine = True
            except:
                pass
            self._is_postgres_engine = is_postgres_engine
        return self._is_postgres_engine
1039453
def emit_db_sequence_updates(engine):
    """"""

    if engine and engine.name == 'postgresql':
        # not implemented for other RDBMS; necessity unknown
        conn = engine.connect()
        qry = """SELECT 'SELECT last_value FROM ' || n.nspname ||
                         '.' || c.relname || ';' AS qry,
                        n.nspname || '.' || c.relname AS qual_name
                 FROM   pg_namespace n
                 JOIN   pg_class c ON (n.oid = c.relnamespace)
                 WHERE  c.relkind = 'S'"""
        for (qry, qual_name) in list(conn.execute(qry)):
            (lastval, ) = conn.execute(qry).first()
            nextval = int(lastval) + 1
            yield "ALTER SEQUENCE %s RESTART WITH %s;" % (qual_name, nextval)
942222
def check_node_runtime!
      stdout, exit_status = Open3.capture2("node", "--version")

      if exit_status.success?
        @node_version = stdout.strip.gsub(/\Av/, "")
        engine.echo "Using Node.js runtime #{ @node_version }."
      else
        raise engine::CompilerError, %{No Node.js runtime has been found in your system.}
      end
      nil
    end
718097
def is_installed(gemname, version=None):
    """"""
    cmdline = ['gem', 'list', '-i', gemname]
    if version:
        cmdline.extend(['-v', version])
    try:
        subprocess.check_output(cmdline, shell=False)
        return True
    except (OSError, subprocess.CalledProcessError) as err:
        if err.returncode == 1:
            return False
        else:
            raise error.ButcherError(
                'Failure running gem. Error was: %s. Output: %s', err,
                err.output)
933255
def detect_version():
    """"""
    version_regex = re.compile(r'\(PostgreSQL\) (?P<major>\d)\.(?P<minor>\d)\.(?P<bugfix>\d)')
    pg_version = None
    with hide('running', 'stdout', 'stderr'):
        output = run('psql --version')
    match = version_regex.search(output)
    if match:
        result = match.groupdict()
        if 'major' in result and 'minor' in result:
            pg_version = u'%(major)s.%(minor)s' % result
    if not pg_version:
        abort(u"Error: Could not determine Postgres version of the server.")
    return pg_version
594844
def is_processed(self, db_versions):
        
        return self.number in (v.number for v in db_versions if v.date_done)
546995
public function setup_is_unicodedb() {
        // Get PostgreSQL server_encoding value
        $sql = "SHOW server_encoding";
        $this->query_start($sql, null, SQL_QUERY_AUX);
        $result = pg_query($this->pgsql, $sql);
        $this->query_end($result);

        if (!$result) {
            return false;
        }
        $rawcolumn = pg_fetch_object($result);
        $encoding = $rawcolumn->server_encoding;
        pg_free_result($result);

        return (strtoupper($encoding) == 'UNICODE' || strtoupper($encoding) == 'UTF8');
    }
300407
def run_migration(connection, queries, engine):
    

    # Execute query
    with connection.cursor() as cursorMig:
        # Parse statements
        queries = parse_statements(queries, engine)

        for query in queries:
            cursorMig.execute(query)
        connection.commit()

    return True
995895
def select_save_engine(engine, paralleled=False):
    '''
    
    '''
    if engine in ['tushare', 'ts', 'Tushare']:
        return sts
    elif engine in ['tdx']:
        if paralleled:
            return stdx_parallelism
        else:
            return stdx
    elif engine in ['gm', 'goldenminer']:
        return sgm
    elif engine in ['jq', 'joinquant']:
        return sjq
    else:
        print('QA Error QASU.main.py call select_save_engine with parameter %s is None of  thshare, ts, Thshare, or tdx', engine)
136384
def check_extension(conn, extension: str) -> bool:
    """"""

    query = 'SELECT installed_version FROM pg_available_extensions WHERE name=%s;'

    with conn.cursor() as cursor:
        cursor.execute(query, (extension,))
        result = cursor.fetchone()

    if result is None:
        raise psycopg2.ProgrammingError(
            'Extension is not available for installation.', extension
        )
    else:
        extension_version = result[0]

        return bool(extension_version)
580696
def _is_valid_script_engine(zap, engine):
    """"""
    engine_names = zap.script.list_engines
    short_names = [e.split(' : ')[1] for e in engine_names]

    return engine in engine_names or engine in short_names
1354414
function() {

    // set the docker env
    env.setDockerEnv();

    // Return whether we have the engine executable in the expected location
    var which = kbox.util.shell.which(DOCKER_EXECUTABLE);
    if (which.toUpperCase() === DOCKER_EXECUTABLE.toUpperCase()) {
      return Promise.resolve(true);
    }

    // We are not installed
    return Promise.resolve(false);

  }
154536
def check_engine(handle):
    """"""
    if handle == 'help':
        dump_engines()
        sys.exit(0)

    if handle not in engines.engines:
        print('Engine "%s" is not available.' % (handle,), file=sys.stderr)
        sys.exit(1)
1104518
def output(self):
        
        return PostgresTarget(
            host=self.host,
            database=self.database,
            user=self.user,
            password=self.password,
            table=self.table,
            update_id=self.update_id,
            port=self.port
        )
1280836
def run(self):
        
        connectable = engine_from_config(
            self._config.get_section(self._config.config_ini_section),
            prefix='sqlalchemy.',
            poolclass=pool.NullPool)

        with connectable.connect() as connection:
            ensureSchemaExists(connectable, self._schemaName)

            context.configure(
                connection=connection,
                target_metadata=self._targetMetadata,
                include_object=self._includeObjectFilter,
                include_schemas=True,
                version_table_schema=self._schemaName
            )

            with context.begin_transaction():
                context.run_migrations()
210696
def pg_isready(self):
        """"""

        cmd = [self._pgcommand('pg_isready'), '-p', self._local_address['port'], '-d', self._database]

        # Host is not set if we are connecting via default unix socket
        if 'host' in self._local_address:
            cmd.extend(['-h', self._local_address['host']])

        # We only need the username because pg_isready does not try to authenticate
        if 'username' in self._superuser:
            cmd.extend(['-U', self._superuser['username']])

        ret = subprocess.call(cmd)
        return_codes = {0: STATE_RUNNING,
                        1: STATE_REJECT,
                        2: STATE_NO_RESPONSE,
                        3: STATE_UNKNOWN}
        return return_codes.get(ret, STATE_UNKNOWN)
884801
def is_sqlatype_integer(coltype: Union[TypeEngine, VisitableType]) -> bool:
    
    coltype = _coltype_to_typeengine(coltype)
    return isinstance(coltype, sqltypes.Integer)