Fastest check if row exists in PostgreSQL

前端 未结 8 1313
有刺的猬
有刺的猬 2020-11-28 19:20

I have a bunch of rows that I need to insert into table, but these inserts are always done in batches. So I want to check if a single row from the batch exists in the table

8条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 20:06

    If you think about the performace ,may be you can use "PERFORM" in a function just like this:

     PERFORM 1 FROM skytf.test_2 WHERE id=i LIMIT 1;
      IF FOUND THEN
          RAISE NOTICE ' found record id=%', i;  
      ELSE
          RAISE NOTICE ' not found record id=%', i;  
     END IF;
    

提交回复
热议问题