我有两张桌子:
CREATE TABLE filedata_temp
(
num serial NOT NULL,
id integer,
mydata character(25),
the_geom geometry,
CONSTRAINT filedata_pkey PRIMARY KEY (num)
)
CREATE TABLE filedata
(
num serial NOT NULL,
id integer,
mydata character(25),
the_geom geometry,
CONSTRAINT filedata_temp_pkey PRIMARY KEY (num)
)
如果第二个表中不存在此行,我想创建从第一个表中插入行到第二个表中的函数。比较表的字段是num
字段。
阅读一些示例后:
CREATE OR REPLACE FUNCTION insert_into_wgs()
RETURNS void AS
$BODY$
BEGIN
insert into filedata
(
id,
mydata,
the_geom,
)
values
(
id,
mydata,
ST_TRANSFORM(the_geom,4326)
);
end
$BODY$
LANGUAGE 'plpgsql'
所以我需要一些帮助/
更新
我试试这个功能(数据库之神告诉我)
CREATE OR REPLACE FUNCTION insert_into_wgs()
RETURNS void AS
$$
BEGIN
INSERT INTO filedata (id,mydata,the_geom)
SELECT id,mydata,ST_TRANSFORM(the_geom,4326)
FROM filedata_temp
WHERE id NOT IN (SELECT id FROM filedata);
end;
$$
LANGUAGE 'plpgsql'
但是没有插入表文件数据。
函数调用
ce_proc = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgis","postgres","123456");
CallableStatement proc = (CallableStatement) ce_proc.prepareCall("{call insert_into_wgs()}");
proc.execute();