Skip to main content
Question

Insert into multiples tables and manage foreign keys

  • April 16, 2019
  • 7 replies
  • 125 views

arnaud974
Contributor
Forum|alt.badge.img+3

Hi,

I need to insert data into different tables and some of them are linked by a relationship (example : a table that contains buildings and a table with the parcels). I need all the parcels to be insert into the database before to start the insert of the building as I want to know for each building the unique ID (generated by a PostgreSQL serial type) of the related parcel.

All my Readers are linked to a single FeatureWriter. Is there a way to specify that this feature writer must process the data one after the other (the order is defined by the list in featureTypes) ? Or any other possibility ?

 

Thanks
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

7 replies

david_r
Celebrity
  • 8394 replies
  • April 16, 2019

There are several ways of doing this, but personally I like using multiple FeatureWriters and chain them with a FeatureMerger set on a dummy merge criteria (e.g. 1 = 1).

The pattern looks like this:

This will ensure that the Master features have all been written and committed before the Detail features.

Here's also an article from Safe with some alternative strategies:

https://knowledge.safe.com/articles/44622/working-with-foreign-keys-writing-database-tables.html


arnaud974
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • 8 replies
  • April 17, 2019

Hi @david_r,

Thanks for your solution.

 

Could you please just show me a picture of the content of the dialog box of FeatureMerger please ?

 

I dont't understand very well where to put the dummy merge criteria.

Thanks


david_r
Celebrity
  • 8394 replies
  • April 17, 2019

This is what I had in mind, simply typing the same hard-coded value in the Requestor and Suplier join criteria:

This would be what's often called an "unconditional merge", meaning that every requestor is joined with every supplier.


arnaud974
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • 8 replies
  • April 17, 2019

This is what I had in mind, simply typing the same hard-coded value in the Requestor and Suplier join criteria:

This would be what's often called an "unconditional merge", meaning that every requestor is joined with every supplier.

I'll try it and I'll let you know if it is working for me !

 

Thanks

arnaud974
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • 8 replies
  • June 5, 2019

There are several ways of doing this, but personally I like using multiple FeatureWriters and chain them with a FeatureMerger set on a dummy merge criteria (e.g. 1 = 1).

The pattern looks like this:

This will ensure that the Master features have all been written and committed before the Detail features.

Here's also an article from Safe with some alternative strategies:

https://knowledge.safe.com/articles/44622/working-with-foreign-keys-writing-database-tables.html

Hi @david_r,

I've finally been able to find some time to test your solution.

 

Something is probably wrong with my settings as the process stops with this error raised: "EXTRA_REFERENCEE_FEATURE"

 

Do you have any idea on what is wrong ?

 

 

Thanks for your help

arnaud974
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • 8 replies
  • June 5, 2019

Hi @david_r,

I've finally been able to find some time to test your solution.

 

Something is probably wrong with my settings as the process stops with this error raised: "EXTRA_REFERENCEE_FEATURE"

 

Do you have any idea on what is wrong ?

 

 

Thanks for your help

I may have found a solution by activating "Process Duplicate Suppliers" and set Build Aggregates and the just after add a Deaggregator process.

 

It seems to work...

 

Would you have done it like that?

david_r
Celebrity
  • 8394 replies
  • June 5, 2019

Hi @david_r,

I've finally been able to find some time to test your solution.

 

Something is probably wrong with my settings as the process stops with this error raised: "EXTRA_REFERENCEE_FEATURE"

 

Do you have any idea on what is wrong ?

 

 

Thanks for your help

The message means that you have more than one supplier for a requestor in the FeatureMerger. You can try enabling the option "Process duplicate suppliers" in the FeatureMerger. Try leaving the associated options as-is.