# How to generate an sql comment using a migration file?

**URL:** <https://discuss.rubyonrails.org/t/how-to-generate-an-sql-comment-using-a-migration-file/57645>\
**Category:** rubyonrails-talk\
**Created:** [March 2, 2011, 5:35pm UTC](https://discuss.rubyonrails.org/t/how-to-generate-an-sql-comment-using-a-migration-file/57645 "2011-03-02T17:35:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [March 2, 2011, 5:35pm UTC](https://discuss.rubyonrails.org/t/how-to-generate-an-sql-comment-using-a-migration-file/57645/1 "2011-03-02T17:35:45Z")

</div>

I'd like to use migrations to add/remove/modify columns from a database. Rails makes that relatively painless. One feature I don't see is the ability to comment on columns in the schema. How can I add a column comment to a migration?

We're using Oracle/PosgreSQL (and we're thinking of adding SQL Server in the future.)

The SQL for adding a comment to a column is oddly enough the same for all three it seems but I'd rather not take a chance.

COMMENT ON COLUMN table\_name.column\_name IS 'Random Comment';

Thanks in advance,

M

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [March 3, 2011, 6:30am UTC](https://discuss.rubyonrails.org/t/how-to-generate-an-sql-comment-using-a-migration-file/57645/2 "2011-03-03T06:30:29Z")

</div>

Jason Cameron wrote in post #984994:

> I'd like to use migrations to add/remove/modify columns from a database. Rails makes that relatively painless. One feature I don't see is the ability to comment on columns in the schema. How can I add a column comment to a migration?
> 
> We're using Oracle/PosgreSQL (and we're thinking of adding SQL Server in the future.)
> 
> The SQL for adding a comment to a column is oddly enough the same for all three it seems but I'd rather not take a chance.
> 
> COMMENT ON COLUMN table\_name.column\_name IS 'Random Comment';

It's possible run whatever SQL you like using "execute" in a migration. I don't think this is a common enough problem to add to the DSL of migrations.

So for the above add this to your migration:

execute "COMMENT ON COLUMN table\_name.column\_name IS 'Random Comment'"
