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 5941279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:05:16+00:00 2026-05-22T16:05:16+00:00

On rails 2.3.11 I’m trying to update multiple rows in a table with values

  • 0

On rails 2.3.11

I’m trying to update multiple rows in a table with values from a different column in each different row (specifically I’m adding timestamps to a table that already existed, using rails migrations).

At first I thought that update_all might work, but it seems that is only for updating multiple rows with the same value.

I resorted to using a SQL statement to get what I wanted (date is the column that already existed, which I am using as an initial value for my timestamps):

execute <<-SQL
  UPDATE tablename SET created_at = date;
SQL

Is there a better ‘rails way’ of doing this?

  • 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-05-22T16:05:16+00:00Added an answer on May 22, 2026 at 4:05 pm

    You should be able to reference another field in update_all. Your problem is most likely the fact that date is a SQL keyword.

    See if this works:

    Model.update_all('tablename.created_at = tablename.date')
    

    If not you might have to quote date but it will be different in different databases.

    MySQL:

    Model.update_all('`created_at` = `date`')
    

    SQLite:

    Model.update_all('"created_at" = "date"')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Rails 2.3.5 I have a view displaying 'employee' records in a table where each
Rails 3.1, ActiveAdmin 0.3.4. My question is somewhat similar to this one but different
rails 2.3.4, sqlite3 I'm trying this Production.find(:all, :conditions => ["time > ?", start_time.utc], :order
rails: I have 'create' and 'update' using the same partial '_form' but the url
Rails is returning the wrong date from my database records. For my model (Target),
Rails 2, PDFkit 0.5.0 Im generating a PDF from a View in Rails 2
Rails loads controllers, helpers and models on each request. My controllers have a bunch
Rails 2.3.5 For a link_to image_tag', I've been trying to figure out how to
Rails model: Categories have items Trying to get a list of categories that actually
Rails provides filter_parameter_logging to filter sensitive parameters from the rails log. If you have

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.