Commit 809f3f81 authored by Alice Salsé's avatar Alice Salsé
Browse files

alter column

parent 56629b43
......@@ -56,11 +56,11 @@ for pathInput in [r'../config/csv/{}'.format(_schemaname)] :
if len(recs)>0:
pass
#TODO ALTER COLUMN when exists
# _sql.append("ALTER TABLE {}.{} \
# ALTER COLUMN {} TYPE {} {} {} {} {};".format(_schemaname, t,
# *row[1:5],
# ['DEFAULT '+[row[5],'\''+row[5]+'\''][type(row[5])==str and '()' not in row[5]],''][row[5] ==''],
# ['REFERENCES '+_reference+['',' ON DELETE CASCADE'][row[4]=='UNIQUE PRIMARY KEY'],''][row[6] =='']))
_sql.append("ALTER TABLE {}.{} \
ALTER COLUMN {} TYPE {} {} {} {} {};".format(_schemaname, t,
*row[1:5],
['DEFAULT '+[row[5],'\''+row[5]+'\''][type(row[5])==str and '()' not in row[5]],''][row[5] ==''],
['REFERENCES '+_reference+['',' ON DELETE CASCADE'][row[4]=='UNIQUE PRIMARY KEY'],''][row[6] =='']))
else :
_sql.append("ALTER TABLE {}.{} \
ADD COLUMN {} {} {} {} {} {};".format(_schemaname, t,
......@@ -72,7 +72,7 @@ for pathInput in [r'../config/csv/{}'.format(_schemaname)] :
_sql_create[t]=[]
_sql_create[t].append("{} {} {} {} {} {}".format(*row[1:5],
['DEFAULT '+[row[5],'\''+row[5]+'\''][type(row[5])==str and '()' not in row[5]],''][row[5] ==''],
['REFERENCES '+_reference,''][row[6] =='']))
['REFERENCES '+_reference+['',' ON DELETE CASCADE'][row[4]=='UNIQUE PRIMARY KEY'],''][row[6] =='']))
_sql.append("COMMENT ON COLUMN {}.{}.{} IS '{}{}';".format(_schemaname, t, row[1], row[7].replace("'","''"), [' ('+row[8].replace("'","''")+')', ''][row[8] =='']))
for i, k in enumerate(_sql_create):
_sql.insert(i,"CREATE TABLE {}.{} (\n{}\
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment