On Tuesday, September 18, 2012 10:50:08 AM UTC-5, Jeremy Evans wrote:
>
> On Monday, September 17, 2012 6:36:48 PM UTC-7, Ben Sullivan wrote:
>>
>> Can I use Sequel to determine the size of table fields - that is the
>> maximum number of characters in a string/varchar field, precision on a
>> float field, max value in an integer field.
>>
>
> For max length of a char/varchar field, yes, you can, but I don't think
> this information is directly exposed.
>
DB.schema(table) returns some of that information but is database specific:
PostgreSQL
[[:id, {:oid=>23, :db_type=>"integer",
:default=>"nextval('visitors_id_seq'::regclass)", :allow_null=>false,
:primary_key=>true, :type=>:integer, :ruby_default=>nil}], [:site_id,
{:oid=>23, :db_type=>"integer", :default=>nil, :allow_null=>false,
:primary_key=>false, :type=>:integer, :ruby_default=>nil}], [:token,
{:oid=>1043, :db_type=>"character varying(40)", :default=>nil,
:allow_null=>false, :primary_key=>false, :type=>:string,
:ruby_default=>nil}], [:useragent, {:oid=>1043, :db_type=>"character
varying(1024)", :default=>nil, :allow_null=>false, :primary_key=>false,
:type=>:string, :ruby_default=>nil}], [:created_at, {:oid=>1114,
:db_type=>"timestamp without time zone", :default=>nil, :allow_null=>false,
:primary_key=>false, :type=>:datetime, :ruby_default=>nil}], [:buoy,
{:oid=>20, :db_type=>"bigint", :default=>nil, :allow_null=>false,
:primary_key=>false, :type=>:integer, :ruby_default=>nil}], [:offset,
{:oid=>20, :db_type=>"bigint", :default=>nil, :allow_null=>false,
:primary_key=>false, :type=>:integer, :ruby_default=>nil}]]
SQL Server
[[:id, {:type=>:integer, :db_type=>"int", :default=>nil,
:allow_null=>false, :primary_key=>true, :column_size=>10, :scale=>0,
:ruby_default=>nil}], [:site_id, {:type=>:integer, :db_type=>"int",
:default=>nil, :allow_null=>false, :primary_key=>false, :column_size=>10,
:scale=>0, :ruby_default=>nil}], [:token, {:type=>:string,
:db_type=>"nchar", :default=>nil, :allow_null=>false, :primary_key=>false,
:column_size=>40, :scale=>nil, :ruby_default=>nil}], [:useragent,
{:type=>:string, :db_type=>"varchar", :default=>nil, :allow_null=>true,
:primary_key=>false, :column_size=>1024, :scale=>nil, :ruby_default=>nil}],
[:created_at, {:type=>:datetime, :db_type=>"datetime", :default=>nil,
:allow_null=>true, :primary_key=>false, :column_size=>23, :scale=>3,
:ruby_default=>nil}], [:buoy, {:type=>:integer, :db_type=>"bigint",
:default=>nil, :allow_null=>true, :primary_key=>false, :column_size=>19,
:scale=>0, :ruby_default=>nil}]]
Rohit
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sequel-talk/-/P-wY1MP8WF0J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.