Project

General

Profile

« Previous | Next » 

Revision 2759

csv2db: Add column indexes on errors table. Use typed_cols and `.to_Col()` to iterate over columns to add indexes on, for the main and errors tables.

View differences:

bin/csv2db
63 63
        def esc_name(name): return sql.esc_name(db, name)
64 64
        sql.run_query(db, 'SET search_path TO '+esc_name(schema))
65 65
        
66
        typed_cols = [sql_gen.TypedCol('row_num', 'serial')]+[
67
            sql_gen.TypedCol(v, 'text') for v in col_names]
68
        
66 69
        def load_():
67 70
            log('Creating table')
68
            typed_cols = [sql_gen.TypedCol('row_num', 'serial')]+[
69
                sql_gen.TypedCol(v, 'text') for v in col_names]
70 71
            sql.create_table(db, table, typed_cols)
71 72
            
72 73
            # Create COPY FROM statement
......
111 112
        db.db.commit()
112 113
        
113 114
        log('Adding indexes')
114
        for name in col_names:
115
            log('Adding index on '+name)
116
            sql.add_index(db, sql_gen.Col(name, table))
115
        for col in typed_cols[1:]: # exclude pkey
116
            log('Adding index on '+col.name)
117
            sql.add_index(db, col.to_Col(), table)
117 118
            db.db.commit()
118 119
        
119 120
        log('Vacuuming table')
......
129 130
            sql_gen.TypedCol('error', 'text NOT NULL'),
130 131
            ]
131 132
        sql.create_table(db, errors_table, typed_cols, has_pkey=False)
133
        for col in typed_cols: sql.add_index(db, col.to_Col(), errors_table)
132 134
        index_cols = ['column', sql_gen.EnsureNotNull('value'), 'error_code',
133 135
            'error']
134 136
        sql.add_index(db, index_cols, errors_table, unique=True)

Also available in: Unified diff