As a beginner in PostgreSQL, I am writing a shell script to verify whether all data have been copied to the child table. I will then perform other activities. If all data have not been copied, the remaining code execution should be halted. In my script, all data from the purchase_history_pre_partitioning
table are copied to the newly created purchase_history
table using the insert into
command.
To verify whether all data have been copied, I have written the following DO statement to compare the number of rows in the two tables. However, there is a syntax error. Please advise me on how to troubleshoot this.
DO statement:
do $$ begin if (((select count(*) from purchase_history) != (select count(*) from purchase_history_pre_partitioning))) then EXIT end $$
Error:
ERROR: syntax error at or near "end" LINE 7: end
^SQL state: 42601 Character: 143
2
Answers
Try this code. It will make sure that all of the data from the purchase_history_pre_partitioning table is correctly moved to the PostgreSQL purchase_history table:
Hope it works 🙂
You are meant to add a semicolon at the end of every SQL statement. Modify your script by adding a semicolon to
EXIT
, also end the if statement usingEND IF