Show data in table from Rails Console for PostgreSQL
11,143
You can get this information from postgres directly from the command line
psql your_development_database -c "\d"
-- lists all database tables
psql your_development_database -c "\d users"
-- lists all columns for a table; 'users' in this case
If you want to look at Model attributes in the rails console
User.new
User.new.inspect
# or install the awesome_print gem for better output
ap User.new
Author by
Jensky
Updated on June 25, 2022Comments
-
Jensky almost 2 years
I find something like this: Rails: How to list database tables/objects using the Rails console?
This line is fine:
ActiveRecord::Base.connection.tables
and returns all tables
but
ActiveRecord::Base.connection.table_structure("users")
generate error:
ActiveRecord::Base.connection.table_structure("projects")
I think that
table_structure
is not Postgres method.
How can I list all data from the table in Rails console for Postgres database?
-
grooble over 6 yearsdon't forget: \q to exit the psql console. just saved you a search ;)
-
house9 over 6 years@grooble - the above is using the
-c
option so it executes the command but does not enter an interactivepsql
session, no need to\q
in that case