On Wednesday, June 11, 2014 8:54:26 AM UTC-7, Luan wrote:
>
> Hi everyone,
>
> Here is my code:
>
> #!/usr/bin/env ruby
>
> require 'rubygems'
> require 'sequel'
>
>
> puts ENV['DB_USER']
> puts ENV['DB_NAME']
> db_connect  = "postgres://" + ENV['DB_USER'] + "@localhost/" + 
> ENV['DB_NAME']
> DB = Sequel.connect(db_connect) # Uses the postgres adapter "Starting 
> ...geting stock info:\n\n"
>
> h = Hash.new
> h['name'] = 'String'
> h['age'] = 'Integer'
>
> DB.create_table!(:tests) do
>   primary_key :id
>   #String :name
>   h.each do |field, type|
>     column field, type
>   end
> end
>
> ------
>
>
> When I replace 
> h['name'] = 'String' to h['name'] = 'Varchar' then it worked 
>
> However, I thought I could use the same as in the documentation where we 
> can put String and it uses varchar or text depends on db. I am using 
> Postgres.
>
> create_table(:columns_types) do  # database type used
>   column :a1, :string            # string
>   column :a2, String             # varchar(255)
>   column :a3, 'string'           # string
>   column :a4, :datetime          # datetime
>   column :a5, DateTime           # timestamp
>   column :a6, 'timestamp(6)'     # timestamp(6)
> end
>
>
> Thanks,
>
> Luan
>
> Error Message:
>
> /Users/luan/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/sequel-4.10.0/lib/sequel/adapters/postgres.rb:161:in
>  
> `async_exec': PG::UndefinedObject: ERROR:  type "string" does not exist 
> (Sequel::DatabaseError)
> LINE 1: ...TE TABLE "tests" ("id" serial PRIMARY KEY, "name" String, "a...
>

Just as the documentation says, if you use 'string' (or any symbol or 
string), it will use that value verbatim. As PostgreSQL doesn't have a type 
named string, it raises an error.

If you want to use the generic type support, you have to use a class:

h = Hash.new
h['name'] = String
h['age'] = Integer
 
Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to