Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8016287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:29:52+00:00 2026-06-04T20:29:52+00:00

DBMS is PostgreSQL. In controller: @data = current_user.myitems.all(:select => ‘record_date, count(record_date) as value’, :group

  • 0

DBMS is PostgreSQL.

In controller:

@data = current_user.myitems.all(:select => 'record_date, count(record_date) as value', :group => 'record_date')

In a view:

<% @data.each do |item| -%>
   <%= item.record_date.utc.strftime('%Y%m%d') %>
<% end -%>

Everything is working fine.

But if I change date field name:

@data = current_user.myitems.all(:select => 'record_date as recdate, count(record_date) as value', :group => 'record_date')

<% @data.each do |item| -%>
   <%= item.recdate.utc.strftime('%Y%m%d') %>
<% end -%>

I get the error message:

undefined method `utc' for "2012-02-09 17:03:47":String

WTF??!! I did not order to cast the type to string!!!

You may suggest not to make an alias in SQL string or to define aliases in model, but I do not want to change models to make aliases for columns, as I need aliases only once and for display purposes only. Controller’s method has “case” statement where multiple select statements are present, each with its own column names. I need to make aliases to have solid view, without “if” statements.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:29:54+00:00Added an answer on June 4, 2026 at 8:29 pm

    You get the types of a postgres query via
    ftype.
    ActiveRecord uses this information in the postgres adapter (method
    #result_as_array) to check wherever columns need escaping then
    throws away this information.

    My guess on the further data flow would be that it takes the column
    name and uses the data gained via reflection from the database to
    determine the type. Since the basic type is String, you get that.
    So, use the column types rails expects or hack the postgres adapter
    and ActiveRecord to ask the column types via ftype.

    tl;dr: Alias the stuff on the Ruby side (in the model somewhere) AR
    doesn’t like what you’re doing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My team needs a DBMS like DynamoDB to store large amount of data, principally
I use MySQL DBMS for storing my data. I've lot of mathematical data to
I am using Django and Postgresql as my DBMS. I wish to set a
I want to write application which uses Postgresql as DBMS. To write client application
My target DBMS's are both Oracle and MySQL SELECT users.* , hr_orders.position_label , hr_orders.is_boss
What DBMS do you use with Erlang ? and Why ?
I am looking for free DBMS options for a localhost environment, which will support
I'm working on a basic DBMS as a pet project and planning to prototype
I use H2 Database as DBMS from a remote computer,so I enabled remote access
How to compare parts of date in Informix DBMS: I wrote the following query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.