Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2009
    Posts
    54

    Unanswered: append to existing data

    I've found this with google, but it doesn't seem to work. How can I append data without rewriting the existing data?

    Code:
    table1 (tablename)
    id values
    1 text1
    2 text2
    3 text3
    
    Let the table1 contains two fields id and value. U need to append some text
    to the existing values. is it ?
    ok...use the following postgresql query .
    update table1 set values = values || 'newtext' where id = 1
    
    || ------> string concat operator
    
    This will result in
    
    table1
    id values
    1 text1newtext
    2 text2
    3 text3

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    "doesn't seem to work" is not enough information to go on

    please show your exact query
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Feb 2009
    Posts
    54
    this is it:
    Code:
    update my_table set my_column = values || 'my_append' where my_table_id = 8;
    ERROR:  column "values" does not exist

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    does your table have a column called values? if not, then that's your error

    (by the way, "values" is a poor choice for a column name, because it's a reserved word)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Feb 2009
    Posts
    54
    No I understand, in the example I did find on the internet I got confused with the "values" column, I thought that " = values || " meant: "append to the values present". Now I've changed to:
    update my_table set my_column = my_column || 'my_append' where my_table_id = 8;

    and everything works as expected.
    Thanks a lot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •