# Detect column type?

**URL:** <https://www.ruby-forum.com/t/detect-column-type/157398>\
**Category:** Rails\
**Created:** [January 10, 2009, 6:11pm UTC](https://www.ruby-forum.com/t/detect-column-type/157398 "2009-01-10T18:11:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [January 10, 2009, 6:11pm UTC](https://www.ruby-forum.com/t/detect-column-type/157398/1 "2009-01-10T18:11:38Z")

</div>

Using column\_names I can get a nice list of columns in a table, but is  
there any way to detect the column _type?_ Like “string”, “integer”,  
“boolean”, etc?

---

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [January 10, 2009, 6:15pm UTC](https://www.ruby-forum.com/t/detect-column-type/157398/2 "2009-01-10T18:15:23Z")

</div>

On 10 Jan 2009, at 17:11, Taylor S.  
\<removed\_email\_address@domain.invalid

> wrote:

> Using column\_names I can get a nice list of columns in a table, but is  
> there any way to detect the column _type?_ Like “string”, “integer”,  
> “boolean”, etc?

The columns method returns an array of column objects, which among  
other things, has the name and type of the corresponding column.

Fred

---

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [January 10, 2009, 6:35pm UTC](https://www.ruby-forum.com/t/detect-column-type/157398/3 "2009-01-10T18:35:07Z")

</div>

Frederick C. wrote:

> On 10 Jan 2009, at 17:11, Taylor S.  
> \<removed\_email\_address@domain.invalid
> 
> > wrote:
> 
> > Using column\_names I can get a nice list of columns in a table, but is  
> > there any way to detect the column _type?_ Like “string”, “integer”,  
> > “boolean”, etc?
> 
> The columns method returns an array of column objects, which among  
> other things, has the name and type of the corresponding column.
> 
> Fred

Indeed. It returns the below for an id column. Thanks.

#\<ActiveRecord::ConnectionAdapters::SQLiteColumn:0x23736b8  
@precision=nil, @primary=true, @default=nil, @limit=nil, @type=:integer,  
@null=false, @name=“id”, @scale=nil, @sql\_type=“INTEGER”\>
