From: Sharon Rosner Date: 2007-10-20T16:56:08+09:00 Subject: Re: read tables from SQL code > can i read/save with ruby the columns involved in that SQL select? If you use Sequel you can retrieve the columns for arbitrary SQL like this: require 'sequel/mysql' # assuming you're using MySQL DB = Sequel('mysql://localhost/mydb') DB['select * from items'].columns #=> [:id, :name, ...] But if you're already using Sequel why not construct your queries using Ruby instead of SQL, e.g.: dataset = DB.query do from :items where {:name =~ /^abc/ && :price < 100} order_by :name end p dataset.columns dataset.each {|r| p r} You can find more information about Sequel here: http://code.google.com/p/ruby-sequel And you can also get help on Sequel-talk: http://groups.google.com/group/sequel-talk best Sharon