from .base import AlterColumn
from .base import ColumnComment
from .base import compiles
+from .base import format_column_name
from .base import format_table_name
from .base import format_type
from .base import RenameTable
)
return ddl.format(
- table_name=element.table_name,
- column_name=element.column_name,
+ table_name=format_table_name(
+ compiler, element.table_name, element.schema
+ ),
+ column_name=format_column_name(compiler, element.column_name),
comment=comment,
)
--- /dev/null
+.. change::
+ :tags: bug, postgresql
+ :tickets: 637
+
+ Fixed issue where COMMENT directives for PostgreSQL failed to correctly
+ include an explicit schema name, as well as correct quoting rules for
+ schema, table, and column names. Pull request courtesy Matthew Sills.
context.assert_(
"ALTER TABLE foo.t ALTER COLUMN c SET NOT NULL",
- "COMMENT ON COLUMN t.c IS 'This is a column comment'",
+ "COMMENT ON COLUMN foo.t.c IS 'This is a column comment'",
)
@config.requirements.comments_api
comment="This is a column comment",
)
- context.assert_("COMMENT ON COLUMN t.c IS 'This is a column comment'")
+ context.assert_(
+ "COMMENT ON COLUMN foo.t.c IS 'This is a column comment'"
+ )
+
+ @config.requirements.comments_api
+ def test_alter_column_add_comment_table_and_column_quoting(self):
+ context = op_fixture("postgresql")
+ op.alter_column(
+ "T",
+ "C",
+ existing_type=Boolean(),
+ schema="foo",
+ comment="This is a column comment",
+ )
+
+ context.assert_(
+ 'COMMENT ON COLUMN foo."T"."C" IS \'This is a column comment\''
+ )
@config.requirements.comments_api
def test_alter_column_add_comment_quoting(self):
)
context.assert_(
- "COMMENT ON COLUMN t.c IS 'This is a column ''comment'''"
+ "COMMENT ON COLUMN foo.t.c IS 'This is a column ''comment'''"
)
@config.requirements.comments_api
existing_comment="This is a column comment",
)
- context.assert_("COMMENT ON COLUMN t.c IS NULL")
+ context.assert_("COMMENT ON COLUMN foo.t.c IS NULL")
@config.requirements.comments_api
def test_create_table_with_comment(self):