I need an array with the column names of a table
Any ideas how I can do this with rails 3.0.0rc?
Columns attribute of the dataframe returns the column labels of the dataframe. You can get the column names as an array by using the . columns. values property of the dataframe.
sp_columns procedure To get the column name of a table we use sp_help with the name of the object or table name. sp_columns returns all the column names of the object. The following query will return the table's column names: sp_columns @table_name = 'News'
In SQL Server, you can select COLUMN_NAME from INFORMATION_SCHEMA. COLUMNS .
Suppose you have a Post model:
Post.column_names # or Post.columns.map { |column| column.name }
It will return an array with column names of the table 'posts'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With