How do I fetch column names from a db table into an array, using PostgreSQL and Ruby?
问题 How can I iterate through all of the column headers in a table for a given database and add each column name individually to an array? I know I can gather all of the information from the table using SELECT * FROM my_table but I need to work with just the column headers at this point. What is the best way to accomplish this? 回答1: Are you using the pg gem? If so, you can try this: require 'pg' # `db_config` must contain your database configuration conn = PG::Connection.open(db_config) column