# How do you copy a fileds content to newly added field?

**URL:** <https://www.ruby-forum.com/t/how-do-you-copy-a-fileds-content-to-newly-added-field/131902>\
**Category:** Rails\
**Created:** [March 14, 2008, 8:11am UTC](https://www.ruby-forum.com/t/how-do-you-copy-a-fileds-content-to-newly-added-field/131902 "2008-03-14T08:11:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![erwinquita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e56c9b/32.png) [@erwinquita](https://www.ruby-forum.com/u/erwinquita)\
**Post date:** [March 14, 2008, 8:11am UTC](https://www.ruby-forum.com/t/how-do-you-copy-a-fileds-content-to-newly-added-field/131902/1 "2008-03-14T08:11:44Z")

</div>

Hi All,

I’ve just finished extracting and saving all the info from my database  
and I need to copy the contents from “description” field to the newly  
created fields “meta\_description” and “meta\_keywords” How do you do  
this? I don’t want my existing data to get messed up. Any help would be  
appreciated. Thanks.

I’ve successfully added the new meta description and keywords using  
migrations  
``

```

$ ./script/generate migration
remove_description_and_keyword_from_content description:text
keyword:text
exists db/migrate
create
db/migrate/003_remove_description_and_keyword_from_content.rb

```

_and here’s my database schema_

```

ActiveRecord::Schema.define(:version => 2) do

  create_table "contents", :force => true do |t|
    t.string "title"
    t.string "description" #<--- How do you copy all data from this
field
    t.text "detail"
    t.string "image"
    t.string "product"
    t.string "link"
    t.float "price"
    t.string "other"
    t.string "target"
    t.float "cost"
    t.string "shipping"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.text "meta_description" #<--- to here and
    t.text "meta_keyword" #<--- Here
  end

end

```

- Erwin Q.

---

<div class="post-metadata">

**Author:** ![erwinquita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e56c9b/32.png) [@erwinquita](https://www.ruby-forum.com/u/erwinquita)\
**Post date:** [March 14, 2008, 8:20am UTC](https://www.ruby-forum.com/t/how-do-you-copy-a-fileds-content-to-newly-added-field/131902/2 "2008-03-14T08:20:15Z")

</div>

update table contents set meta\_description = description, meta\_keyword  
= description;

back up your database first before doing any of this stuff of course.

Mike

---

<div class="post-metadata">

**Author:** ![erwinquita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e56c9b/32.png) [@erwinquita](https://www.ruby-forum.com/u/erwinquita)\
**Post date:** [March 14, 2008, 9:15am UTC](https://www.ruby-forum.com/t/how-do-you-copy-a-fileds-content-to-newly-added-field/131902/3 "2008-03-14T09:15:24Z")

</div>

Hi Mike

is this a rake task? I tried it and it gave me an error  
rake aborted!  
Don’t know how to build task ‘update’

update table contents set meta\_description = description, meta\_keyword  
= description;

Thanks for the quick reply

---

<div class="post-metadata">

**Author:** ![erwinquita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e56c9b/32.png) [@erwinquita](https://www.ruby-forum.com/u/erwinquita)\
**Post date:** [March 14, 2008, 9:23am UTC](https://www.ruby-forum.com/t/how-do-you-copy-a-fileds-content-to-newly-added-field/131902/4 "2008-03-14T09:23:57Z")

</div>

Mike,

I’m sorry forgot that it’s a mysql statement, I tried it on mysql but  
gave me this error

mysql\> UPDATE table contents SET meta\_description = description,  
meta\_keyword = description;  
ERROR 1064 (42000): You have an error in your SQL syntax; check the  
manual that corresponds to your MySQL server version for the right  
syntax to use near ‘table contents SET meta\_description = description,  
meta\_keyword = description’ at line 1

How do you properly construct it. Thanks again.

---

<div class="post-metadata">

**Author:** ![erwinquita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e56c9b/32.png) [@erwinquita](https://www.ruby-forum.com/u/erwinquita)\
**Post date:** [March 14, 2008, 9:30am UTC](https://www.ruby-forum.com/t/how-do-you-copy-a-fileds-content-to-newly-added-field/131902/5 "2008-03-14T09:30:53Z")

</div>

Erwin Q. wrote:

> mysql\> UPDATE table contents SET meta\_description = description,  
> meta\_keyword = description;  
> ERROR 1064 (42000): You have an error in your SQL syntax; check the

Just: UPDATE contents SET …

---

<div class="post-metadata">

**Author:** ![erwinquita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e56c9b/32.png) [@erwinquita](https://www.ruby-forum.com/u/erwinquita)\
**Post date:** [March 14, 2008, 9:42am UTC](https://www.ruby-forum.com/t/how-do-you-copy-a-fileds-content-to-newly-added-field/131902/6 "2008-03-14T09:42:52Z")

</div>

Mark

Thank you so much! Indeed a success! Thanks again!

mysql\> update contents set meta\_description = description, meta\_keyword  
= description;  
Query OK, 989 rows affected (0.29 sec)  
Rows matched: 989 Changed: 989 Warnings: 0

Mark B. wrote:

> Erwin Q. wrote:
> 
> > mysql\> UPDATE table contents SET meta\_description = description,  
> > meta\_keyword = description;  
> > ERROR 1064 (42000): You have an error in your SQL syntax; check the
> 
> Just: UPDATE contents SET …

---

<div class="post-metadata">

**Author:** ![erwinquita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e56c9b/32.png) [@erwinquita](https://www.ruby-forum.com/u/erwinquita)\
**Post date:** [March 14, 2008, 7:24pm UTC](https://www.ruby-forum.com/t/how-do-you-copy-a-fileds-content-to-newly-added-field/131902/7 "2008-03-14T19:24:06Z")

</div>

oops… thanks Mark, it was late when I posted that!

Mike
