(tablename, src_curs, dst_curs, column_list = [], condition = None,
        dst_tablename = None, dst_column_list = None,
        write_hook = None, flush_hook = None)
return (buf.total_bytes, buf.total_rows)
COPY table from one db to another.
COPY table from one db to another.
COPY table from one db to another .
def full_copy(tablename, src_curs, dst_curs, column_list = [], condition = None,
        dst_tablename = None, dst_column_list = None,
        write_hook = None, flush_hook = None):
    """COPY table from one db to another."""

    # default dst table and dst columns to source ones
    dst_tablename = dst_tablename or tablename
    dst_column_list = dst_column_list or column_list[:]
    if len(dst_column_list) != len(column_list):
        raise Exception('src and dst column lists must match in length')

    def build_qfields(cols):
        if cols:
            return ",".join([skytools.quote_ident(f) for f in cols])
        else:
            return "*"

    def build_statement(table, cols):
        qtable = skytools.quote_fqident(table)
        if cols:
            qfields = build_qfields(cols)
            return "%s (%s)" % (qtable, qfields)
        else:
            return qtable

    dst = build_statement(dst_tablename, dst_column_list)
    if condition:
        src = "(SELECT %s FROM %s WHERE %s)" % (build_qfields(column_list),
                                                skytools.quote_fqident(tablename),
                                                condition)
    else:
        src = build_statement(tablename, column_list)

    if hasattr(src_curs, 'copy_expert'):
        sql_to = "COPY %s TO stdout" % src
        sql_from = "COPY %s FROM stdin" % dst
        buf = CopyPipe(dst_curs, sql_from = sql_from)
        buf.write_hook = write_hook
        buf.flush_hook = flush_hook
        src_curs.copy_expert(sql_to, buf)
    else:
        if condition:
            # regular psycopg copy_to generates invalid sql for subselect copy
            raise Exception('copy_expert() is needed for conditional copy')
        buf = CopyPipe(dst_curs, dst)
        buf.write_hook = write_hook
        buf.flush_hook = flush_hook
        src_curs.copy_to(buf, src)
    buf.flush()

    return (buf.total_bytes, buf.total_rows)
def full_copy ( tablename , src_curs , dst_curs , column_list = [ ] , condition = None , dst_tablename = None , dst_column_list = None , write_hook = None , flush_hook = None ) : # default dst table and dst columns to source ones dst_tablename = dst_tablename or tablename dst_column_list = dst_column_list or column_list [ : ] if len ( dst_column_list ) != len ( column_list ) : raise Exception ( 'src and dst column lists must match in length' ) def build_qfields ( cols ) : if cols : return "," . join ( [ skytools . quote_ident ( f ) for f in cols ] ) else : return "*" def build_statement ( table , cols ) : qtable = skytools . quote_fqident ( table ) if cols : qfields = build_qfields ( cols ) return "%s (%s)" % ( qtable , qfields ) else : return qtable dst = build_statement ( dst_tablename , dst_column_list ) if condition : src = "(SELECT %s FROM %s WHERE %s)" % ( build_qfields ( column_list ) , skytools . quote_fqident ( tablename ) , condition ) else : src = build_statement ( tablename , column_list ) if hasattr ( src_curs , 'copy_expert' ) : sql_to = "COPY %s TO stdout" % src sql_from = "COPY %s FROM stdin" % dst buf = CopyPipe ( dst_curs , sql_from = sql_from ) buf . write_hook = write_hook buf . flush_hook = flush_hook src_curs . copy_expert ( sql_to , buf ) else : if condition : # regular psycopg copy_to generates invalid sql for subselect copy raise Exception ( 'copy_expert() is needed for conditional copy' ) buf = CopyPipe ( dst_curs , dst ) buf . write_hook = write_hook buf . flush_hook = flush_hook src_curs . copy_to ( buf , src ) buf . flush ( ) return ( buf . total_bytes , buf . total_rows )