Exemplo n.º 1
0
def _create_csv(cur: psycopg2.extensions.cursor, filename: str,
                select_stmnt: str):
    """Create or update given csv file with db data for given select statement."""
    with open(f'exports/{filename}.csv', 'wb') as csvfile:
        cur.copy_expert(f'COPY ({select_stmnt}) to stdout with csv header',
                        csvfile)
    return f'{filename}.csv'
def view_contents(cursor: psycopg2.extensions.cursor, view: str, timestamp: int) -> str:
    """Return True if a SELECT from the VIEW matches the expected string."""
    stream = io.StringIO()
    query = f"COPY (SELECT * FROM {view} WHERE mz_logical_timestamp() > {timestamp}) TO STDOUT"
    try:
        cursor.copy_expert(query, stream)  # type: ignore
    except psycopg2.errors.InternalError_:  # type: ignore
        # The view is not yet ready to be queried
        raise ViewNotReady()
    return stream.getvalue().strip()
Exemplo n.º 3
0
def view_matches(cursor: psycopg2.extensions.cursor, view: str,
                 expected: str) -> bool:
    """Return True if a SELECT from the VIEW matches the expected string."""
    stream = io.StringIO()
    try:
        cursor.copy_expert(f"COPY (SELECT * FROM {view}) TO STDOUT", stream)
    except psycopg2.errors.InternalError_:
        # The view is not yet ready to be queried
        return False
    return stream.getvalue() == expected