Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何为postgres中的不同记录在同一个表中插入相同的数据(或复制)_Sql_Postgresql - Fatal编程技术网

Sql 如何为postgres中的不同记录在同一个表中插入相同的数据(或复制)

Sql 如何为postgres中的不同记录在同一个表中插入相同的数据(或复制),sql,postgresql,Sql,Postgresql,我有一个名为记录的表,其数据如下- Section_one | section_two | values | cDate name_Fit | hellp0 | present | 2014-08-23 name_Fit | onew | parcel | 2014-08-21 name_Fit | twow | new thing | 2014-07-04 现在,我正在尝试将一个名为name\u

我有一个名为记录的表,其数据如下-

Section_one | section_two | values       | cDate

name_Fit    | hellp0      | present      | 2014-08-23
name_Fit    | onew        | parcel       | 2014-08-21
name_Fit    | twow        | new thing    | 2014-07-04
现在,我正在尝试将一个名为
name\u Fit\u one
w.r.t的新数据插入到列
section\u one
,该列应具有与其对应的类似数据(w.r.t column
section\u two
值)

我试图编写sql来实现这一点,但我在postgres上遇到了错误。谁能纠正我做错了什么

Insert into records(section_one,section_two,values) Values ('name_Fit_one', select section_two,values from records where section_one='name_Fit');
预期结果

Section_one | section_two | values       | cDate

name_Fit    | hellp0      | present      | 2014-08-23
name_Fit    | onew        | parcel       | 2014-08-21
name_Fit    | twow        | new thing    | 2014-07-04
name_Fit_one| hellp0      | present      | 2014-08-29
name_Fit_one| onew        | parcel       | 2014-08-29
name_Fit_one| twow        | new thing    | 2014-08-29
需要编写将一条记录的内容复制到另一条记录的单个查询吗

下面是它的sql提琴-


请注意,
values
是一个保留字,因此需要引用。

如果您使用的是postgresql,您应该能够使用:

Insert into records
  select 'name_Fit_one', section_two, values, '2014-08-29'
    from records
   where section_one = 'name_Fit';
小提琴:

注意,我重命名了一些列,因为不清楚上面的示例或SQLFIDLE是否包含实际数据和列名(它们不同)


如果您希望将文字“2014-08-29”替换为当前的插入日期,则可以将其替换为运行插入的日期。

您的标签上显示postgresql,但您的SQLFIDLE是mysql。你真正使用的是什么数据库?您的数据也显示“值”列,但您的小提琴显示“值”,这是正确的吗?cdate也是一个时间戳字段(如在小提琴中)还是一个日期字段(如在上面的数据中)?
Insert into records
  select 'name_Fit_one', section_two, values, '2014-08-29'
    from records
   where section_one = 'name_Fit';