ロード中に、データが重複していないことを確認する検証手順を作成しようとしています。Verticaはこれをネイティブにサポートしていません:
Verticaは、データがロードされたときではなく、クエリが実行されたときに制約違反をチェックします。ロードプロセスの一部として制約違反を検出するには、NO COMMITオプションを指定したCOPY(ページ667)ステートメントを使用します。データをコミットせずにロードすることにより、ANALYZE_CONSTRAINTS関数を使用してデータのロード後チェックを実行できます。関数が制約違反を検出した場合、コミットしていないため、ロードをロールバックできます。
問題は、これをプログラムで行う方法がわからないことです。ストアドプロシージャが必要だと思いますが、verticaのストアドプロシージャの構文/制限に精通していません。手伝ってくれますか?これが私が持っているものです:
-- Create a new table. "id" is auto-incremented and "name" must be unique
CREATE TABLE IF NOT EXISTS my_table (
id IDENTITY
, name varchar(50) UNIQUE NOT NULL
, type varchar(20)
, description varchar(200)
);
--Insert a record
begin;
copy my_table from stdin
abort on error
NO COMMIT; -- this begins the load
name1|type1|description1 --this is the load
\. -- this closes the load
commit;
-- insert the duplicate record
begin;
copy my_table from stdin
abort on error
NO COMMIT; -- this begins the load
name1|type1|description1 --this is the load
\. -- this closes the load
commit; -- Surprisingly, the load executes successfully! What's going on?!?!
-- Check constraints. We see that there is a failed constraints:
select analyze_constraints('my_table');
私の考えは、いくつかの条件付きロジックを実行することです。疑似コードは以下のとおりです。Verticaの準備を手伝ってもらえますか?
Begin
load data
if (select count(*) from (select analyze_constraints('my_table')) sub) == 0:
commit
else rollback