2017-09-06 84 views
0

我已將以下內容插入到Postgres的custom_property表中。插入是基於p.pk_pirana,在這種情況下是12128.我想要做的是更新所有信息都正確的記錄,除了我想將值字段從「2」更新爲「1」?對於adsl_mode的pk_custom_property ID將爲每個fk_pirana改變插入後根據Postgres中的特定ID更新/編輯多行記錄

INSERT INTO custom_property 
(pk_custom_property, fk_pirana, key, value, 
type, fk_updated_by, updated_date 
) 
SELECT nextval('seq_pk_custom_property') AS pk_custom_property, 
p.pk_pirana AS fk_pirana, 
'adsl_mode' AS key, 
'2' AS value, 
1 AS type, 
1 AS fk_updated_by, 
now() AS updated_date 
FROM pirana p 
WHERE p.pk_pirana IN (12128,12435,54643,23453,432436,....continued for 400 more IDs); 

Gets inserted into the table as a row: 

pk_custom_property | fk_pirana |  key  | value | type | fk_updated_by |  updated_date   
--------------------+-----------+---------------+-------+------+---------------+---------------------------- 
       30947 |  12128 | asad.down |  | 3 |   15367 | 2017-04-22 09:43:50.859 

       30949 |  12128 | psdasd | 0  | 3 |   15367 | 2017-04-22 09:44:38.579 
      32555 |  12128 | adsl_mode  | 2  | 1 |    1 | 2017-09-06 07:04:10.416511 
+1

'更新custom_property設定值= 1,其中fk_pirana = 12128'?.. –

回答

0
update custom_property 
    set value =2 
where fk_pirana = 12128,12435,54643,23453,432436,....continued for 400 more IDs) 
AND key ='adsl_mode'; 
+0

請使用您的問題編輯鏈接添加額外的信息。後回答按鈕應該只用於問題的完整答案。 - [來自評論](/ review/low-quality-posts/17248734) –