Project

General

Profile

« Previous | Next » 

Revision 3094

sql.py: Added distinct_table()

View differences:

sql.py
1223 1223
def empty_db(db, schema='public', **kw_args):
1224 1224
    '''For kw_args, see tables()'''
1225 1225
    for table in tables(db, schema, **kw_args): truncate(db, table, schema)
1226

  
1227
def distinct_table(db, table, distinct_on):
1228
    '''Creates a copy of a temp table which is distinct on the given columns.
1229
    The table will get an index on these columns, facilitating merge joins.
1230
    @param table Will be renamed to the distinct on table.
1231
    @return The old table.
1232
    '''
1233
    if distinct_on == []: return table # already distinct
1234
    
1235
    old_table = copy.copy(table)
1236
    table.name = sql_gen.concat(table.name, '_distinct')
1237
    
1238
    copy_table_struct(db, old_table, table)
1239
    add_index(db, distinct_on, table, unique=True)
1240
    insert_select(db, table, None, mk_select(db, old_table, start=0),
1241
        ignore=True)
1242
    analyze(db, table)
1243
    
1244
    return old_table

Also available in: Unified diff