Revision 2675
Added by Aaron Marcuse-Kubitza over 12 years ago
sql.py | ||
---|---|---|
873 | 873 |
run_query(db, 'ALTER TABLE '+table+' ADD COLUMN '+row_num_col |
874 | 874 |
+' serial NOT NULL PRIMARY KEY', log_level=3) |
875 | 875 |
|
876 |
def create_table(db, table, cols): |
|
877 |
'''Creates a table. |
|
878 |
* The first column becomes the primary key. |
|
879 |
* Each column gets an index. |
|
880 |
@param cols [sql_gen.TypedCol,...] The column names and types. |
|
881 |
''' |
|
882 |
table = sql_gen.as_Table(table) |
|
883 |
|
|
884 |
pkey = cols.pop(0) |
|
885 |
str_ = 'CREATE TABLE '+table.to_str(db)+' (\n' |
|
886 |
str_ += ' '+pkey.to_str(db)+' NOT NULL PRIMARY KEY\n' |
|
887 |
for col in cols: str_ += ' , '+col.to_str(db)+'\n' |
|
888 |
str_ += ');\n' |
|
889 |
run_query(db, str_, cacheable=True, log_level=2) |
|
890 |
|
|
891 |
for col in cols: add_index(db, sql_gen.Col(col.name, table)) |
|
892 |
|
|
876 | 893 |
def tables(db, schema_like='public', table_like='%'): |
877 | 894 |
module = util.root_module(db.db) |
878 | 895 |
params = {'schema_like': schema_like, 'table_like': table_like} |
Also available in: Unified diff
sql.py: Added create_table()