Changeset: 19cddbd0ab54 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/19cddbd0ab54 Modified Files: sql/backends/monet5/rel_bin.c sql/server/rel_dump.c sql/test/pg_regress/Tests/alter_table.test Branch: check Log Message:
allow ALTER TABLE ... ADD COLUMN ... CHECK statements diffs (148 lines): diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c --- a/sql/backends/monet5/rel_bin.c +++ b/sql/backends/monet5/rel_bin.c @@ -5988,7 +5988,15 @@ sql_update_check(backend *be, sql_key * { mvc *sql = be->mvc; int pos = 0; + + + stack_push_frame(be->mvc, "ALTER TABLE ADD CONSTRAINT CHECK"); + sql_schema* ss = key->t->s; + frame_push_table(sql, key->t); + key->t->s = ss; // recover the schema because frame_push_table removes it + sql_rel* rel = rel_read(sql, sa_strdup(sql->sa, key->check), &pos, sa_list(sql->sa)); + stack_pop_frame(sql); sql_rel* base = rel->l; assert(strcmp(((sql_exp*) updates->exps->h->data)->alias.name, TID) == 0); list_append(base->exps, exp_copy(sql, updates->exps->h->data)); diff --git a/sql/server/rel_dump.c b/sql/server/rel_dump.c --- a/sql/server/rel_dump.c +++ b/sql/server/rel_dump.c @@ -2030,7 +2030,9 @@ rel_read(mvc *sql, char *r, int *pos, li skipWS(r, pos); if (!(s = mvc_bind_schema(sql, sname))) return sql_error(sql, ERR_NOTFOUND, SQLSTATE(3F000) "No such schema '%s'\n", sname); - if (!(t = mvc_bind_table(sql, s, tname))) + if (stack_has_frame(sql, "ALTER TABLE ADD CONSTRAINT CHECK") && !(t = frame_find_table(sql, tname))) + return sql_error(sql, ERR_NOTFOUND, SQLSTATE(42S02) "Table missing '%s.%s'\n", sname, tname); + if (!t && !(t = mvc_bind_table(sql, s, tname))) return sql_error(sql, ERR_NOTFOUND, SQLSTATE(42S02) "Table missing '%s.%s'\n", sname, tname); if (isMergeTable(t)) return sql_error(sql, -1, SQLSTATE(42000) "Merge tables not supported under remote connections\n"); diff --git a/sql/test/pg_regress/Tests/alter_table.test b/sql/test/pg_regress/Tests/alter_table.test --- a/sql/test/pg_regress/Tests/alter_table.test +++ b/sql/test/pg_regress/Tests/alter_table.test @@ -1618,13 +1618,13 @@ create table p1 (f1 int) statement ok create table c1 (f1 int, f2 text, f3 int) -statement error +statement ok alter table p1 add column a1 int check (a1 > 0) statement ok alter table p1 add column f2 text -statement error +statement ok insert into p1 values (1,2,'abc') statement error @@ -1633,16 +1633,22 @@ insert into c1 values(11,'xyz',33,0) statement error insert into c1 values(11,'xyz',33,22) -query IT rowsort +query IIT rowsort select * from p1 ---- +1 +2 +abc -statement error +statement ok update p1 set a1 = a1 + 1, f2 = upper(f2) -query IT rowsort +query IIT rowsort select * from p1 ---- +1 +3 +ABC statement ok drop table c1 cascade @@ -1723,10 +1729,10 @@ alter table foo alter f1 TYPE varchar(10 statement ok drop table foo -statement error +statement ok create table anothertab (atcol1 bigint GENERATED ALWAYS AS IDENTITY check (atcol1 <= 3), atcol2 boolean) -statement error +statement ok insert into anothertab (atcol1, atcol2) values (default, true) statement error @@ -1738,7 +1744,7 @@ insert into anothertab (atcol2) values ( statement error insert into anothertab (atcol2) values (false) -statement error +statement ok select * from anothertab statement error @@ -1747,7 +1753,7 @@ alter table anothertab alter column atco statement error alter table anothertab alter column atcol1 type integer -statement error +statement ok select * from anothertab statement error @@ -1759,7 +1765,7 @@ insert into anothertab (atcol1, atcol2) statement error insert into anothertab (atcol2) values (null) -statement error +statement ok select * from anothertab statement error @@ -1768,14 +1774,14 @@ alter table anothertab alter column atco when atcol2 is false then 'IT WAS FALSE' else 'IT WAS NULL!' COMMIT -statement error +statement ok select * from anothertab statement error alter table anothertab alter column atcol1 type boolean using case when atcol1 % 2 = 0 then true else false COMMIT -statement error +statement ok alter table anothertab alter column atcol1 drop default statement error @@ -1789,10 +1795,10 @@ statement error alter table anothertab alter column atcol1 type boolean using case when atcol1 % 2 = 0 then true else false COMMIT -statement error +statement ok select * from anothertab -statement error +statement ok drop table anothertab statement ok _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org