Reputation: 4080
I would like to get a list of schemas in the current database from the rails console. Currently, I am executing raw sql to get the info via
ActiveRecord::Base.connection.execute("select schema_name from information_schema.schemata")
Is there a more correct way to retrieve this information from the rails console with ActiveRecord?
Upvotes: 3
Views: 4306
Reputation: 2125
i have tried the following ,it works for me.
data = ActiveRecord::Base.connection.execute('select * from information_schema.schemata')
data.each do |schema|
puts schema['schema_name']
end
it returns the schema names.
Upvotes: 7
Reputation: 7124
The SQL query you used is very correct. Information schema is part of SQL standard.
ActiveRecord does not have a ready method for this.
So it seems there is no better way.
Upvotes: 3