# PostgreSQL datatypes equivalent when scaffolding

**URL:** <https://www.ruby-forum.com/t/postgresql-datatypes-equivalent-when-scaffolding/151637>\
**Category:** Rails\
**Created:** [October 23, 2008, 6:16pm UTC](https://www.ruby-forum.com/t/postgresql-datatypes-equivalent-when-scaffolding/151637 "2008-10-23T18:16:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![The\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@The\_N](https://www.ruby-forum.com/u/The_N)\
**Post date:** [October 23, 2008, 6:16pm UTC](https://www.ruby-forum.com/t/postgresql-datatypes-equivalent-when-scaffolding/151637/1 "2008-10-23T18:16:42Z")

</div>

Hi, I’m trying to make a scaffold for my test application using  
PostgreSQL 8.3 database. and I remembered on an article for MySQL it  
uses :string for VARCHAR, :integer for INT, and :text for TINYTEXT,  
TEXT, MEDIUMTEXT, or LONGTEXT2.

Is there any datatype equivalent with PostgreSQL?

My database is like this

workers:  
id serial (primary key)  
first\_name character(50)  
last\_name character(50)

users:  
id serial (primary key)  
username character(20)  
password character(20)  
id\_personnel integer(11) (foreign key related with the ‘id’ field of  
the ‘workers’ table)

Additionally, is there a way to import or, rather, migrate the tables’  
properties (their fields and datatypes) to rails? If there is any,  
that would be great, because my database is created and would like to  
use it without doing the “rake db:migrate” thing.

I hope I’m not asking too much. Thanks in advance.

Greetings…  
The N.

---

<div class="post-metadata">

**Author:** ![The\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@The\_N](https://www.ruby-forum.com/u/The_N)\
**Post date:** [October 24, 2008, 11:33am UTC](https://www.ruby-forum.com/t/postgresql-datatypes-equivalent-when-scaffolding/151637/2 "2008-10-24T11:33:38Z")

</div>

Migrations in Rails are independent from your DB. I have successfully  
migrated a Rails app from MySQL to PostgreSQL without having to change a  
single line of migration.

---

<div class="post-metadata">

**Author:** ![The\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@The\_N](https://www.ruby-forum.com/u/The_N)\
**Post date:** [October 24, 2008, 3:08pm UTC](https://www.ruby-forum.com/t/postgresql-datatypes-equivalent-when-scaffolding/151637/3 "2008-10-24T15:08:17Z")

</div>

On Oct 25, 4:33 am, Fernando P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ## Migrations in Rails are independent from your DB. I have successfully migrated a Rails app from MySQL to PostgreSQL without having to change a single line of migration.
> 
> Posted viahttp://www.ruby-forum.com/.

And what about constraint (primary and foreign keys) and things like  
that. I know “:string” really mean “character varying” and I need the  
equivalent of the “character” data type, which is not present in the  
Rails’s data type.

I hope to be wrong but another alternative would be to use the  
“execute” command followed by the SQL query. Is it possible to do so  
as mentioned in this article?  
[http://www.robbyonrails.com/articles/2005/11/11/rails-migrations-and-postgresql-constraints](http://www.robbyonrails.com/articles/2005/11/11/rails-migrations-and-postgresql-constraints).  
(Yeah I know it’s old but it can work on my project’s migrations)

Later…

The N.
