sql-update

Update postgreql database with Node.js

ぐ巨炮叔叔 提交于 2020-01-06 06:36:29
问题 I try to Update a table on postgresql so for that i'm creating two arrays var name_ = []; var id_ = []; then i creat a forEach loop where MyRow is the query that contain different data MyRow.rows.forEach(function(row){ name_.push(row.name); id_.push(row.id); }); var updateAccount = 'UPDATE myTable SET myRow =$1 '+ 'where id = $2' client.query(updateAccount,[name_.toString(),id_.toString()],false).then(function(err,result){ if (err) { console.log(err.stack); } else { console.log(name_) } });

SQL Updating column in new table with arithmetic function from column in another table

半城伤御伤魂 提交于 2020-01-06 06:07:36
问题 I have two tables: part of Table1: id | per | va | gp | minutes -----+-------+-------+----+--------- 1 | 11.87 | 14.5 | 69 | 16.1 2 | 17.07 | 154.9 | 78 | 23.9 3 | 4.30 | -8.6 | 21 | 4.4 4 | 5.68 | -42.2 | 52 | 9.3 5 | 19.46 | 347.8 | 82 | 32.1 6 | 18.26 | 125.3 | 47 | 23.3 7 | 12.76 | 79.0 | 82 | 28.5 8 | 9.19 | -3.7 | 13 | 14.8 9 | 21.15 | 10.7 | 10 | 6.8 10 | 14.38 | 46.1 | 31 | 25.7 Table2: player | prl | position --------+-------------------------+---------- 1 | | 2 | | 3 | | 4 | | I'm

update table with 4 columns specified, but only 2 columns are available

荒凉一梦 提交于 2020-01-05 09:14:55
问题 I have one table called test, which has 4 columns: id INT v_out INT v_in INT label CHARACTER I'm trying to update the table with the following query: String sql = " update test set v_out = temp.outV , v_in = temp.inV , label = temp.label from ( values( (1,234,235,'abc') ,(2,234,5585,'def') ) ) as temp (e_id, outV, inV, label) where id = temp.e_id "; When I execute it, I got the error: org.postgresql.util.PSQLException: ERROR: table "temp" has 2 columns available but 4 columns specified Whats

how to update primary key value in sql?

萝らか妹 提交于 2020-01-05 08:38:33
问题 I have a country table which have a column Countryid I accidently deleted the CountryId Which Had value=1 and now in state table there is a value of column countryId=1 which is used to fetch the records (states) according to country id. I had inserted the country again but it has different id so how can I update the value again in country table of CountryId which primary key from 2 to 回答1: The direct answer to your question is to use set identity_insert off . The best place to start is with

PostgreSQL 8.2: Require specific column to be present in UPDATE statement

痞子三分冷 提交于 2020-01-05 06:09:25
问题 I would like to force user to specify origin of update to some table (sometbl), eg. to specify 'local' or 'remote' (for col2) - but checking of that requirement should occur at DB level when UPDATE statement is executed so: UPDATE sometbl SET col1 = 'abc'; should throw error (exception), but: UPDATE sometbl SET col1 = 'abc', col2 = 'remote'; ...will succeed. I tried to create BEFORE update trigger for that table, but I was unable to check if NEW.col2 was explictly set. I used condition IF NEW

CodeIgniter update_batch without replacing the previous data next updated value will puts by comma separated as increment

走远了吗. 提交于 2020-01-05 05:30:09
问题 Although I am not sure. update_batch is it possible to without replacing the previous data next updated value will puts by comma separated as an array-form on the SAME FILED . I shown 2 Demo image for better understand. My Code is already running for only batch update But not for update_batch increment value without replacing previous data! For example - For 1st time update , column field will shown like this at "t_franchise_price" column --- For 2nd time When next update will perform , then

MySQL How to insert new record or update a field depending on whether it exists?

空扰寡人 提交于 2020-01-04 17:26:13
问题 I am trying to implement a rating system where I keep the following two fields in my db table: rating (the current rating) num_rates (the number of ratings submitted so far) UPDATE `mytable` SET rating=((rating*num_rates)+$theRating)/num_rates, num_rates=num_rates+1 WHERE uniqueCol='$uniqueCol' the variables are from my PHP code. So, basically sometimes the row with the uniqueCol does not exist in the DB, so how can I do the above statement if the exists and if it doesn't then do something

Update statement: Error: Target table must be part of an equijoin predicate

喜夏-厌秋 提交于 2020-01-04 05:44:18
问题 I get this error when I try to update a column of Table 1 that is like a column of Table 2. Target table must be part of an equijoin predicate. update test set category = t1.category from category_type t1, test t2 where t2.link ilike '%' || t1.type || '%' and t2.link ilike '%.nike.com/%'; Category_Type Table shown below: type category sandals shoes boots shoes t-shirts apparel -pants apparel 回答1: I don't know Redshift, but in Postgres you must not repeat the target table in the FROM clause of

Postgresql Update inside For Loop

心不动则不痛 提交于 2020-01-04 03:16:06
问题 I'm new enough to postgresql, and I'm having issues updating a column of null values in a table using a for loop. The table i'm working on is huge so for brevity i'll give a smaller example which should get the point across. Take the following table +----+----------+----------+ | id | A | B | C | +----+----------+----------+ | a | 1 | 0 | NULL | | b | 1 | 1 | NULL | | c | 2 | 4 | NULL | | a | 3 | 2 | NULL | | c | 2 | 3 | NULL | | d | 4 | 2 | NULL | +----+----------+----------+ I want to write

MySQL Update rows with double left join, limiting first match

痞子三分冷 提交于 2020-01-03 19:24:27
问题 I have three tables (SQLFiddle with tables created) Orange text is what I need to get by comparing Products.name with Filters.filter. I figured out that substring match can be done like this: on Products.name LIKE CONCAT('%',Filters.filter,'%'); I only need the first filter match to be used. So "Mushroom soup" will match "Soup" and not "Mushroom". What is best approach for this task? A tested SQLFiddle link, if possible, please. What I tried: ( feel free to skip everything below ) Tried