Revision 3065
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
765 | 765 |
@param cond sql_gen.Code WHERE condition. e.g. use sql_gen.*Cond objects. |
766 | 766 |
@param in_place If set, locks the table and updates rows in place. |
767 | 767 |
This avoids creating dead rows in PostgreSQL. |
768 |
* changes may only change one column |
|
769 | 768 |
* cond must be None |
770 | 769 |
@return str query |
771 | 770 |
''' |
... | ... | |
774 | 773 |
for c, v in changes] |
775 | 774 |
|
776 | 775 |
if in_place: |
777 |
assert len(changes) == 1 |
|
778 | 776 |
assert cond == None |
779 | 777 |
|
780 |
col, value = changes[0] |
|
781 |
type_ = db.col_info(sql_gen.with_default_table(col, table)).type |
|
782 |
|
|
783 |
query = ('ALTER TABLE '+table.to_str(db)+' ALTER COLUMN '+col.to_str(db) |
|
784 |
+' TYPE '+type_+'\nUSING '+value.to_str(db)) |
|
778 |
query = 'ALTER TABLE '+table.to_str(db)+'\n' |
|
779 |
query += ',\n'.join(('ALTER COLUMN '+c.to_str(db)+' TYPE ' |
|
780 |
+db.col_info(sql_gen.with_default_table(c, table)).type |
|
781 |
+'\nUSING '+v.to_str(db) for c, v in changes)) |
|
785 | 782 |
else: |
786 | 783 |
query = 'UPDATE '+table.to_str(db)+'\nSET\n' |
787 | 784 |
query += ',\n'.join((c.to_str(db)+' = '+v.to_str(db) |
Also available in: Unified diff
sql.py: mk_update(): in_place: Support updating multiple columns at once