PostgreSQLで記述された関数があり、大きなテーブルを調べて、別のテーブルに大量の値を挿入します。出力は問題なく、大量の行が挿入されているように見えますが、実際にはターゲットテーブル(私のコードでは「resources」テーブル)に値が挿入されていません。
トランザクション内に挿入ステートメントを入れてみましたが、役に立ちませんでした。私が見逃しているある種の厄介なアクセスまたは許可設定はありますか?私がやっているようにこれを行ういくつかの例をウェブ上で見つけたので、私はこれに少し髪を引っ張っています...
これが私の関数です:
DECLARE
datatype_property record;
property record;
new_resource_id bigint;
BEGIN
RAISE NOTICE 'Starting...';
FOR datatype_property IN
SELECT * FROM datatype_properties
LOOP
RAISE NOTICE 'Trying to insert';
if not exists(select * from resources where uri = datatype_property.subject_resource) then
SELECT INTO new_resource_id NEXTVAL('resources_id_seq');
INSERT INTO resources (id, uri) VALUES(
new_resource_id,
datatype_property.subject_resource
);
RAISE NOTICE 'Inserted % with id %',datatype_property.subject_resource, new_resource_id;
end if;
END LOOP;
FOR property IN
SELECT * FROM properties
LOOP
if not exists(select * from resources where uri = property.source_uri) then
SELECT INTO new_resource_id NEXTVAL('resources_id_seq');
INSERT INTO resources (id, uri) VALUES(
new_resource_id,
resource.source_uri
) ;
RAISE NOTICE 'Inserted % with id %',resource.source_uri, new_resource_id;
end if;
if not exists(select * from resources where uri = property.destination_uri) then
SELECT INTO new_resource_id NEXTVAL('resources_id_seq');
INSERT INTO resources (id, uri) VALUES(
new_resource_id,
resource.source_uri
) ;
RAISE NOTICE 'Inserted % with id %',resource.source_uri, new_resource_id;
end if;
END LOOP;
RETURN;
終わり;
編集:次のリンクからの指示でplpgsql言語をアクティブにしました:
http://wiki.postgresql.org/wiki/CREATE_OR_REPLACE_LANGUAGE
編集2:
このコード:
DECLARE
datatype_property record;
property record;
new_resource_id bigint;
BEGIN
insert into resources (id, uri) values ('3', 'www.google.com');
END
どちらも機能しません:O