In Oracle we have a tiny sql file (truncate_table.sql) that calls a function that truncates a table BEGIN DBMS_OUTPUT.PUT_LINE('FuncTruncTable executing...'); IF ( FuncTruncTable(upper('&1'))=FALSE) THEN DBMS_OUTPUT.PUT_LINE('FuncTruncTable failed'); END IF; END; /:
BEGIN
DBMS_OUTPUT.PUT_LINE('FuncTruncTable executing...');
IF ( FuncTruncTable(upper('&1'))=FALSE) THEN
DBMS_OUTPUT.PUT_LINE('FuncTruncTable failed');
END IF;
END;
/
&1 is passed as schema_name.table_nameFor &1
, we pass schema_name.table_name
. I realize that table names in PGPostgreSQL are in lower case.
So, in PGPostgreSQL I tried
IF ( select FuncTruncTable(lower('&1'))=FALSE) THEN....;
IF ( select FuncTruncTable(lower('&1'))=FALSE) THEN....;
This sqlSQL file is called by a shell script (truncate_single_table.shtruncate_single_table.sh
) that basically looks like this
TableName=$1 LOG_FILE=/some_dir/log/truncate_log.txt sqlplus user_name/user_pass @/some_dir/sql/truncate_table.sql $TableName > $LOG_FILE
TableName=$1
LOG_FILE=/some_dir/log/truncate_log.txt
sqlplus user_name/user_pass @/some_dir/sql/truncate_table.sql $TableName > $LOG_FILE
truncate_single_table.sh istruncate_single_table.sh
is called by another shell truncate_tablesscript truncate_tables.sh
.sh
truncate_tables.sh assemblestruncate_tables.sh
assembles a bunch of tables and calls truncate_single_table `truncate_single_table.sh toto truncate them one by one as follows....:
. /some_dir/bin/truncate_single_table.sh schema_name.TABLE_1 NEW
. /some_dir/bin/truncate_single_table.sh schema_name.TABLE_2 APPEND
. /some_dir/bin/truncate_single_table.sh schema_name.TABLE_3 APPEND
. /some_dir/bin/truncate_single_table.sh schema_name.TABLE_1 NEW . /some_dir/bin/truncate_single_table.sh schema_name.TABLE_2 APPEND . /some_dir/bin/truncate_single_table.sh schema_name.TABLE_3 APPEND and and so forth. NEW
NEW
and APPENDAPPEND
are used in order to count the tables - the number of the tables that have to be truncated has to match the number of the actually truncated tables. If an ORA-error occurs, the job sendsends a warning because TotalNumber - number of "ORA-"s <> TotalNumber(TotalNumber - number of errors) <> TotalNumber
.
I'm trying to convert the process to PostgresPostgreSQL. I'm totally new to PGPostgreSQL. Simply replacing sqlplus user_name/user_pass @/some_dir/sql/truncate_table.sql $TableName > $LOG_FILE to psql -d "dbname=$dbname user='user_name' password='user_pass' host=$HostName" -f /some_dir/sql/truncate_gnxsawork_table.sql $TableName > $LOG_FILE
sqlplus user_name/user_pass @/some_dir/sql/truncate_table.sql $TableName > $LOG_FILE
...doesn't with
psql -d "dbname=$dbname user='user_name' password='user_pass' host=$HostName" -f /some_dir/sql/truncate_gnxsawork_table.sql $TableName > $LOG_FILE
doesn't work. Perhaps
Perhaps different options (other than -d-d
, -f-f
) should be used that I'm not aware of.
I'll greatly appreciate any help. ....but, please don't assume that I already know something )))