Search code examples
htmlrubypostgresqlsinatrapgadmin

SQL Statement to update multiple columns with multiple where conditions


So I have the following SQL statement:

db.exec("UPDATE products SET product_description = '#{fj_description}' AND personalization = '#{fj_personalization}' AND product_photo = '#{fj_product_photo}' AND order_information = '#{fj_order_information}' WHERE campaign_name = '#{camp_name}' AND product_type = 'fleecejacket'")

All of the variables are returning the correct text that's retrieved from an HTML input field, so it seems to be something wrong with the sql statement. When I try to update the database, I get this error:

PG::InvalidTextRepresentation at /update_products
ERROR: invalid input syntax for type boolean: "soft, midweight fleece" LINE 1: UPDATE products SET product_description = 'soft, midweight f... ^

Solution

  • Try using comma instead AND:

    "UPDATE products 
     SET product_description = '#{fj_description}',
       personalization = '#{fj_personalization}',
       product_photo = '#{fj_product_photo}',
       order_information = '#{fj_order_information}' 
     WHERE campaign_name = '#{camp_name}' 
     AND product_type = 'fleecejacket'"