Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik and ServiceNow Partner to Bring Trusted Enterprise Context into AI-Powered Workflows. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Pasha23
Contributor
Contributor

Truncate <...> cascade

Hello,

first I will describe what I want to achieve.

We are migrating from MySQL db to PostgreSQL db. I need to truncate PostgreSQL table(s) with all sequences and than add new data from MySQL and restore the sequences. If I'm running a classic job:

tDBInput(MySQL)-->tFileOutputDelimited-->tMap-->tDBOutput-->tLogRow

Where in output I select Truncate and Inser

than this Error appears:

Exception in component tDBOutput_1 (UsersCSV)

org.postgresql.util.PSQLException: ERROR: cannot truncate a table referenced in a foreign key constraint

Detail: Table "user_role" references "users".

Hint: Truncate table "user_role" at the same time, or use TRUNCATE ... CASCADE.

How can I implement Truncante <...> Cascade for this or any other solution to solve this.

Thanks.

Labels (2)
2 Replies
PaulyWally
Contributor III
Contributor III

Can you truncate "user_role"? I assume you can since you are truncating "user". Since there's a referential constraint, any records left in "user_role" would likely be pointless.

 

I am completely speculating based on the little info you gave me! Please ensure truncating "user_role" would not cause any adverse affects!

 

So the answer is likely to truncate "user_role" first.

 

Use a tDBRow prior to the subjob you outlined. Add a truncate query to the tDBRow:

 

TRUNCATE user_role...

 

https://www.postgresql.org/docs/9.1/sql-truncate.html

 

Your flow would look like this:

 

tDBRow --> On Subjob OK --> tDBInput(MySQL) --> tFileOutputDelimited --> tMap --> tDBOutput --> tLogRow

Pasha23
Contributor
Contributor
Author

PaulyWally,

thank you.

I'll try it...