public function execute(string $sql, array $resultTypes = [])
    {
        $result = @pg_query($this->getResource(), $sql);

        if (false === $result) {
            throw new exceptions\InvalidQueryException(pg_last_error($this->getResource()));
        }

        switch (pg_result_status($result)) {
            case PGSQL_COMMAND_OK:
                $rows = pg_affected_rows($result);
                pg_free_result($result);
                return $rows;

            case PGSQL_COPY_IN:
            case PGSQL_COPY_OUT:
                pg_free_result($result);
                return true;

            case PGSQL_TUPLES_OK:
            default:
                return new ResultSet($result, $this->getTypeConverterFactory(), $resultTypes);
        }
    }