Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2017
    Posts
    1

    Unanswered: Infinite recursion in PostgreSQL rule

    I am inserting large amount of data and I am using EF Core as an ORM, and data may have conflicting primary key from times to times due to concurrency. I am trying to create a rule in PostgresSQL in order to intercept the INSERT call and transform it into an INSERT ... ON CONFLICT DO NOTHING. I have defined a rule, however PostgreSQL complains that it has detected an infinite recursion:
    Code:
    CREATE OR REPLACE RULE table1_insert_on_conflict_rule AS
    ON INSERT TO public.table1
    WHERE new.ignore_duplicate_pkey IS TRUE
    DO INSTEAD INSERT INTO table1 (id, col1, ignore_duplicate_pkey) 
    VALUES (new.id, new.col1, false) ON CONFLICT DO NOTHING;
    Any ideas on how can I achieve what I want?

  2. #2
    Join Date
    Nov 2003
    Posts
    2,988
    Provided Answers: 23
    You can use a trigger instead of the rule (rules are somewhat discouraged anyway)
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags: http://www.dbforums.com/misc.php?do=bbcode#code

    Tips for good questions:

    http://tkyte.blogspot.de/2005/06/how...questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •