[英]PostgreSQL Update Issue With Quotation('')
I'm using PostgreSQL & Codeigniter. 我正在使用PostgreSQL和Codeigniter。 There is a table called folio in the database.
数据库中有一个名为folio的表。 It has few columns containing
remarks1, remarks2, remarks3
as well. 它的列很少包含
remarks1, remarks2, remarks3
。 Data for the all the other columns are inserted when the INSERT statement executes for the 1st time. INSERT语句第一次执行时,将插入所有其他列的数据。
When I try to execute below UPDATE statement later for the below 3 columns, remarks1
column get updated correctly. 当我稍后尝试对下面的3列执行下面的UPDATE语句时,
remarks1
列将正确更新。 But remarks2, remarks3
columns are updated with ''
. 但是
remarks2, remarks3
列使用''
更新。
UPDATE "folio" SET "remarks1" = 'test remark', "remarks2" = '', "remarks3" = '' WHERE "id" = '51';
Given that remarks1, remarks2, remarks3
columns data type is character varying
. 给定
remarks1, remarks2, remarks3
列的数据类型是character varying
。 I'm using Codeigniter active records. 我正在使用Codeigniter活动记录。 At a time all 3 columns could be updated else single column could be updated depending on the user input.
一次可以更新所有3列,也可以根据用户输入更新单个列。
What could be the issue? 可能是什么问题? How can I fix this?
我怎样才能解决这个问题? Why columns are updated with
''
? 为什么用
''
更新列?
As requested the php array in CI would be below 根据要求,CI中的php数组将在下面
$data = array(
'remark1' => $this->input->post('remark1'),
'remark2' => $this->input->post('remark1'),
'remark3' => $this->input->post('remark1')
);
Function which saves the data contains below two lines only 保存数据的功能仅包含以下两行
$this->db->where('id', $folio_id);
$this->db->update('folio', $data);
Those columns are updated with ''
because you tell them to? 这些列更新为
''
因为您告诉他们?
Let's take a closer look at the query 让我们仔细看一下查询
UPDATE "folio"
SET
"remarks1" = 'test remark',
"remarks2" = '',
"remarks3" = ''
WHERE
"id" = '51';
First you select the table folio
for the update. 首先,您选择要更新的表
folio
。
Then you tell it to update remarks1
through remarks3
with new values. 然后,您告诉它使用新值更新
remarks1
到remarks3
。 For remarks2
and remarks3
you specify to set them to an empty string. 对于
remarks2
和remarks3
您指定将它们设置为空字符串。 And that's what's going to happen. 这就是将要发生的事情。
Last but not least, you tell it to only apply this update to rows where id
equals 51
. 最后但并非最不重要的一点是,您告诉它仅将此更新应用于
id
等于51
行。
So, in order to only update remarks1
you can simply remove the other columns from your update: 因此,为了仅更新
remarks1
您可以简单地从更新中删除其他列:
UPDATE "folio"
SET
"remarks1" = 'test remark'
WHERE
"id" = '51';
Update: 更新:
I'm by far not a CI expert, but from what I see, I'd change the $data
array to only contain information for remark1
: 我到目前为止还不是CI专家,但是从我的角度来看,我将
$data
数组更改为仅包含有关remark1
信息:
$data = array(
'remark1' => $this->input->post('remark1')
);
And (from my understanding) it should only update this single column. 并且(据我了解),它仅应更新此单列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.