内容简介:翻译自:https://stackoverflow.com/questions/12218185/mysql-replace-into-only-some-fields
表
CREATE TABLE `gfs` (
`localidad` varchar(20),
`fecha` datetime,
`pp` float(8,4) NOT NULL default '0.0000',
`temp` float(8,4) NOT NULL default '0.0000',
PRIMARY KEY (`localidad`,`fecha`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
当我尝试使用此更新字段时
REPLACE INTO gfs(localidad,fecha,pp) VALUES ("some_place","2012-08-05 02:00","1.6")
先前的值en temp将丢失.为什么?
REPLACE
Syntax
所记载并且其他人已经提到过:
07001 is a MySQL extension to the SQL standard. It either inserts, or deletes and inserts. For another MySQL extension to standard SQL—that either inserts or updates—see 07002.
手册继续解释:
Values for all columns are taken from the values specified in the REPLACE
statement. Any missing columns are set to their default values, just as happens for INSERT
. You cannot refer to values from the current row and use them in the new row.
因此,你想要:
INSERT INTO gfs (localidad, fecha, pp)
VALUES ('some_place', '2012-08-05 02:00', 1.6)
ON DUPLICATE KEY UPDATE pp=VALUES(pp);
翻译自:https://stackoverflow.com/questions/12218185/mysql-replace-into-only-some-fields
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
数据结构与算法:Python语言描述
裘宗燕 / 机械工业出版社 / 2016-1 / CNY 45.00
本书基于Python语言介绍了数据结构与算法的基本知识,主要内容包括抽象数据类型和Python面向对象程序设计、线性表、字符串、栈和队列、二叉树和树、集合、排序以及算法的基本知识。本书延续问题求解的思路,从解决问题的目标来组织教学内容,注重理论与实践的并用。一起来看看 《数据结构与算法:Python语言描述》 这本书的介绍吧!