darold / ora2pg

Ora2Pg is a free tool used to migrate an Oracle database to a PostgreSQL compatible schema. It connects your Oracle database, scan it automatically and extracts its structure or data, it then generates SQL scripts that you can load into PostgreSQL.
http://www.ora2pg.com/
GNU General Public License v3.0
978 stars 341 forks source link

Duplicate SQL On Create Trigger #1731

Closed carenswijaya01 closed 4 months ago

carenswijaya01 commented 4 months ago

Hi, i have an issue with ora2pg 24.1.

here's my ora2pg.conf

# ORACLE
ORACLE_DSN       dbi:Oracle:host=$ORACLE_HOST;port=$ORACLE_PORT;service_name=$ORACLE_SERVICE_NAME
ORACLE_USER      $ORACLE_USERNAME
ORACLE_PWD       $ORACLE_PASSWORD
SCHEMA           $ORACLE_USERNAME
# POSTGRES
PG_DSN           dbi:Pg:host=$PSQL_HOST;port=$PSQL_PORT;dbname=$PSQL_DB_NAME
PG_USER          $PSQL_USERNAME
PG_PWD           $PSQL_PASSWORD
PG_VERSION       15
CREATE_SCHEMA      0
PG_SCHEMA        $PSQL_SCHEMA
# EXPORT TYPE
TYPE             TRIGGER
OUTPUT           TRIGGER_output.sql
STOP_ON_ERROR        0
USE_RESERVED_WORDS  1
NULL_EQUAL_EMPTY    0
USE_ORAFCE  1

and some of sql trigger result become like this

CREATE TRIGGER my_trig
    BEFORE INSERT ON my_table my_schema.my_table
BEFORE INSERT
ON my_schema.my_table 
REFERENCING NEW AS New OLD AS Old
FOR EACH ROW
 FOR EACH ROW
    EXECUTE PROCEDURE trigger_fct_my_trig();

not all of it, but most of it become like that

carenswijaya01 commented 4 months ago

Another clue, i found it bug because i use referencing clause on oracle's trigger

darold commented 4 months ago

Please can you past an example of an Oracle trigger DDL that is failing? You can remove the body of the trigger (between the begin and final end).

carenswijaya01 commented 4 months ago

Please can you past an example of an Oracle trigger DDL that is failing? You can remove the body of the trigger (between the begin and final end).

Here my oracle trig

CREATE OR REPLACE TRIGGER SM.TRG_ABSENSI_ONLINE
BEFORE INSERT
ON SM.ABSENSI_ONLINE
REFERENCING NEW AS New OLD AS Old
FOR EACH ROW
DECLARE
tmpVar NUMBER;
BEGIN
....
END TRG_ABSENSI_ONLINE;

And the result on ora2pg

DROP TRIGGER IF EXISTS trg_absensi_online ON absensi_online CASCADE;
CREATE OR REPLACE FUNCTION trigger_fct_trg_absensi_online() RETURNS trigger AS $BODY$
DECLARE
tmpVar bigint;
BEGIN
 ....
RETURN NEW;
END
$BODY$
 LANGUAGE 'plpgsql' SECURITY DEFINER;
-- REVOKE ALL ON FUNCTION trigger_fct_trg_absensi_online() FROM PUBLIC;

CREATE TRIGGER trg_absensi_online
    BEFORE INSERT ON absensi_online TRG_ABSENSI_ONLINE
BEFORE INSERT
ON SM.ABSENSI_ONLINE
REFERENCING NEW AS New OLD AS Old
FOR EACH ROW
 FOR EACH ROW
    EXECUTE PROCEDURE trigger_fct_trg_absensi_online();

It happens only if i use referencing clause, even if i comment that referencing clause, it still duplicate like above, except i remove that clause

darold commented 4 months ago

Commit fb6b0ad fixes this issue.

carenswijaya01 commented 4 months ago

Commit fb6b0ad fixes this issue.

It still have bug in BEFORE INSERT, not just in FOR EACH ROW