Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix alter table drop column drops trigger on the table #3225

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contrib/babelfishpg_tsql/src/tablecmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ lookup_and_drop_triggers(ObjectAccessType access, Oid classId,
return;

/* We only want to execute this function for the DROP TABLE case */
if (classId != RelationRelationId || access != OAT_DROP)
if (classId != RelationRelationId || access != OAT_DROP || subId != 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls add a comment for the subId != 0

return;

/*
Expand Down
33 changes: 33 additions & 0 deletions test/JDBC/expected/alter_table.out
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,36 @@ GO

drop table trans2
GO

--------------------------- BABEL-5417 ---------------------------
------- DROP COLUMN SHOULD NOT DROP TRIGGERS ON THE TABLE --------
CREATE TABLE babel_5417(a int, b int);
GO
CREATE TRIGGER babel_5417_trg
ON babel_5417
AFTER INSERT AS SELECT 1
GO
SELECT tgname FROM pg_trigger WHERE tgname LIKE 'babel_5417%';
GO
~~START~~
varchar
babel_5417_trg
~~END~~

ALTER TABLE babel_5417 DROP COLUMN a
GO
SELECT tgname FROM pg_trigger WHERE tgname LIKE 'babel_5417%';
GO
~~START~~
varchar
babel_5417_trg
~~END~~

DROP TABLE babel_5417
GO
SELECT tgname FROM pg_trigger WHERE tgname LIKE 'babel_5417%';
GO
~~START~~
varchar
~~END~~

10 changes: 0 additions & 10 deletions test/JDBC/expected/db_owner-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,6 @@ go
alter procedure dbo.dbowner__p0 as select 20
go

-- BABEL-5417: Trigger gets dropped if we drop a column in table
create trigger dbo.dbowner__trg0
on dbo.dbowner__t0
after insert
as
begin
select 'New row inserted'
end
go

-- Member of db_owner role should be allowed to rename objects
exec sp_rename 'dbo.dbowner__t0.x', 'x_renamed', 'column'
go
Expand Down
23 changes: 22 additions & 1 deletion test/JDBC/input/alter_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,25 @@ ALTER TABLE trans2 DROP COLUMN AddDate
GO

drop table trans2
GO
GO

--------------------------- BABEL-5417 ---------------------------
------- DROP COLUMN SHOULD NOT DROP TRIGGERS ON THE TABLE --------
CREATE TABLE babel_5417(a int, b int);
GO
CREATE TRIGGER babel_5417_trg
ON babel_5417
AFTER INSERT AS SELECT 1
GO
SELECT tgname FROM pg_trigger WHERE tgname LIKE 'babel_5417%';
GO
ALTER TABLE babel_5417 DROP COLUMN a
GO
SELECT tgname FROM pg_trigger WHERE tgname LIKE 'babel_5417%';
GO
DROP TABLE babel_5417
GO
SELECT tgname FROM pg_trigger WHERE tgname LIKE 'babel_5417%';
GO
------------------------------------------------------------------
------------------------------------------------------------------
10 changes: 0 additions & 10 deletions test/JDBC/input/db_owner-vu-verify.mix
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,6 @@ go
alter procedure dbo.dbowner__p0 as select 20
go

-- BABEL-5417: Trigger gets dropped if we drop a column in table
create trigger dbo.dbowner__trg0
on dbo.dbowner__t0
after insert
as
begin
select 'New row inserted'
end
go

-- Member of db_owner role should be allowed to rename objects
exec sp_rename 'dbo.dbowner__t0.x', 'x_renamed', 'column'
go
Expand Down
Loading