1

When you fire up rails dbconsole you can easily execute commands such as:

select * from users limit 1;

However some commands require using Postgres functions such as now() or timezone(zone, timestamp)

How can you evaluate Postgres functions without needing to select data?

It would be nice to be able to play with some of these functions without having to wrap them into a select statement.

=> now()
# now | 2013-11-18 22:32:48.814876+00

How can I do this directly from dbconsole?

1
  • @zeantsoi's answer is correct, rails dbconsole (with a mysql database) is the equivalent of running mysql -u username -ppassword database_name, it's a raw connection. Commented Nov 18, 2013 at 23:44

1 Answer 1

4

The Rails database console is purely a way to interface with the specified database's command line. It doesn't provide any Rails wrappers or convenience methods – you're limited to whatever the database language provides. In PostgreSQL, the correct query to retrieve the current timestamp with timezone is as follows:

SELECT now();
Sign up to request clarification or add additional context in comments.

2 Comments

Ahah - works a treat. Out of interest do you know how to get that time local to a particular timezone: stackoverflow.com/questions/20059342/… ? Thank you.
I've added an answer, but I'm not sure that it substantially differs from what you've already suggested. Am I missing something?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.