How to use pgtricks - 2 common examples

To help you get started, we’ve selected a few pgtricks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github akaihola / pgtricks / pgtricks / pg_dump_splitsort.py View on Github external
output: Optional[IO[str]] = None
    buf: List[str] = []

    def flush() -> None:
        cast(IO[str], output).writelines(buf)
        buf[:] = []

    def new_output(filename: str) -> IO[str]:
        if output:
            output.close()
        return open(os.path.join(directory, filename), 'w')

    copy_lines: Optional[List[str]] = None
    counter = 0
    output = new_output('0000_prologue.sql')
    matcher = Matcher()

    for line in open(sql_filepath):
        if copy_lines is None:
            if line in ('\n', '--\n'):
                buf.append(line)
            elif line.startswith('SET search_path = '):
                flush()
                buf.append(line)
            else:
                if matcher.match(DATA_COMMENT_RE, line):
                    counter += 1
                    output = new_output(
                        '{counter:04}_{schema}.{table}.sql'.format(
                            counter=counter,
                            schema=matcher.group('schema'),
                            table=matcher.group('table')))
github akaihola / pgtricks / pgtricks / pg_incremental_backup.py View on Github external
def main() -> None:
    opts = parse_arguments()
    output_file = os.path.join(opts.output_dir,
                               '{}.sql'.format(opts.database))
    for path in glob(os.path.join(opts.output_dir, '*.sql')):
        os.remove(path)
    dump_database(opts.database, output_file)
    split_sql_file(output_file)
    os.remove(output_file)
    commit_database(opts.output_dir, opts.remote)

pgtricks

PostgreSQL utilities

BSD-3-Clause
Latest version published 7 months ago

Package Health Score

56 / 100
Full package analysis

Similar packages