Postgresql Insert Update
Rules that are defined on INSERT, UPDATE, and DELETE are significantly different from the view rules described in the previous section. First, their CREATE RULE command allows more:.They are allowed to have no action.They can have multiple actions.They can be INSTEAD or ALSO (the default).The pseudorelations NEW and OLD become useful.They can have rule qualifications.Second, they don't modify the query tree in place. Instead they create zero or more new query trees and can throw away the original one. No qualification, with either ALSO or INSTEADthe query tree from the rule action with the original query tree's qualification added Qualification given and ALSOthe query tree from the rule action with the rule qualification and the original query tree's qualification added Qualification given and INSTEADthe query tree from the rule action with the rule qualification and the original query tree's qualification; and the original query tree with the negated rule qualification addedFinally, if the rule is ALSO, the unchanged original query tree is added to the list. Since only qualified INSTEAD rules already add the original query tree, we end up with either one or two output query trees for a rule with one action.For ON INSERT rules, the original query (if not suppressed by INSTEAD) is done before any actions added by rules.
This allows the actions to see the inserted row(s). But for ON UPDATE and ON DELETE rules, the original query is done after the actions added by rules. This ensures that the actions can see the to-be-updated or to-be-deleted rows; otherwise, the actions might do nothing because they find no rows matching their qualifications.The query trees generated from rule actions are thrown into the rewrite system again, and maybe more rules get applied resulting in more or less query trees. So a rule's actions must have either a different command type or a different result relation than the rule itself is on, otherwise this recursive process will end up in an infinite loop. (Recursive expansion of a rule will be detected and reported as an error.)The query trees found in the actions of the pgrewrite system catalog are only templates. Since they can reference the range-table entries for NEW and OLD, some substitutions have to be made before they can be used. For any reference to NEW, the target list of the original query is searched for a corresponding entry.

If found, that entry's expression replaces the reference. Otherwise, NEW means the same as OLD (for an UPDATE) or is replaced by a null value (for an INSERT).
Postgresql Insert On Conflict
Any reference to OLD is replaced by a reference to the range-table entry that is the result relation.After the system is done applying update rules, it applies view rules to the produced query tree(s). Views cannot insert new update actions so there is no need to apply update rules to the output of view rewriting. Say we want to trace changes to the slavail column in the shoelacedata relation.
So we set up a log table and a rule that conditionally writes a log entry when an UPDATE is performed on shoelacedata.
Postgresql Insert Into
I am a new one in postgreSQL. I have 3 tables, one table references the other 2 table's primary keys. But I couldn't insert data into the Table3. There are a few problems with your tables.
I'll try to address the foreign keys first, since you question asked about them:)But before that, we should realize that the two sets of tables (the first three you created and the second set, which you created after dropping the first set) are the same. It all depends on what do you want to do with the data.First example - you want to have consistent data in all tables, but you try to insert values that doesn't match with Table1.Second example - you don't want to have consistent data, but try to do something else, not exactly know what. Table can't have more than one primary key.Third example - you still don't know what you want to achieve and put UNIQUE constraint on column that may have he same value multiple times.If you just want to insert your data - get rid of foreign key references in first example.
If you want to have consistent data in all tables - do the data cleanup and then insert in tables WITH foreign key constraints.tl;dr: to insert your data into Table3 with code from first example - insert missing values into Table1.DataID column that exist in Table3.DataId.