将值添加到 PostgreSQL 9.3 中现有 table 中新插入的列
Adding values to a newly inserted column in an existing table in PostgreSQL 9.3
创建了一个名为 "collegetable" 的 table:
create table collegetable (stid integer primary key not null,stname
varchar(50),department varchar(10),dateofjoin date);
为每列提供的值:collegetable data
在其中插入了一个名为 "cgpa" 的新列,并尝试使用代码一次性为该列添加值:
WITH col(stid, cgpa) as
( VALUES((1121,8.01),
(1131,7.12),
(1141,9.86))
)
UPDATE collegetable as colldata
SET cgpa = col.cgpa
FROM col
WHERE colldata.stid = col.stid;
出现错误:
ERROR:operator does not exist:integer=record
LINE9:where colldata.stid=col.stid;
HINT:No operator matches the given name and arguement type.you might need to add explicit type casts.
请提前solving.thanks帮忙
with
子句只定义列的名称,不数据类型:
with col (stid, cgpa) as (
...
)
update ...;
有关详细信息,请参阅 tutorial and the full reference
创建了一个名为 "collegetable" 的 table:
create table collegetable (stid integer primary key not null,stname
varchar(50),department varchar(10),dateofjoin date);
为每列提供的值:collegetable data
在其中插入了一个名为 "cgpa" 的新列,并尝试使用代码一次性为该列添加值:
WITH col(stid, cgpa) as
( VALUES((1121,8.01),
(1131,7.12),
(1141,9.86))
)
UPDATE collegetable as colldata
SET cgpa = col.cgpa
FROM col
WHERE colldata.stid = col.stid;
出现错误:
ERROR:operator does not exist:integer=record
LINE9:where colldata.stid=col.stid;
HINT:No operator matches the given name and arguement type.you might need to add explicit type casts.
请提前solving.thanks帮忙
with
子句只定义列的名称,不数据类型:
with col (stid, cgpa) as (
...
)
update ...;
有关详细信息,请参阅 tutorial and the full reference