Stop Liquibase from removing Oracle hints - oracle

I have Oracle statements containing hints. But Liquibase keeps removing them. I guess Liquibase thinks they are block comments ... for some reason.
As such I've tried adding stripComments:false but without any luck.
Example
--changeset AUTHOR:ID (stripComments:false)
Insert /*+ IGNORE_ROW_ON_DUPKEY_INDEX(CUSTOMER,CUSTOMER_PK) */ Into CUSTOMER Values (value1, value2, etc)
Does anyone have an idea of how to stop Liquibase from removing the Oracle hints?

found the issue, forgot to add stripcomments on one changeset

Related

Oracle: check constraints are properly compiled?

Still learning the oracle, today we got one instance that, one of the trigger was compiled with dirty code, so at run time it threw an exception.(on Production Server)
so I just want to know that Is there any way to know that constraints as well as trigger are properly compiled?, just to avoid more instances like this.
Thanks
you mean by dirty code as errors right ? To know trigger or procedures which they are compiled with warning, check user_errors table:
select * from user_errors where name= '<procedure or trigger name>'
as for constraints (Primary key , foreign key , default values) they dont get created if they contains error.

sql cannot operate correctly in Redshift

I want to run sql like:
CREATE TEMPORARY TABLE tmptable AS SELECT * FROM redshift_table WHERE date > #{date};
I can run this sql in command line in Redshift, but if I run it in my program, it doesn't work correctly. When I change CREATE TEMPORARY TABLE to CREATE TABLE it works correctly.
I am using mybatis as OR mapper and driver is:
org.postgresql.Driver
org.postgresql:postgresql:9.3-1102-jdbc41
What's wrong?
I am assuming the #date is an actual date in your actual query.
Having said that, there is not reason this command doesnt work, its as per the syntax listed here,
http://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_TABLE_AS.html
Have you tried posting it on AWS Redshift forums, generally they are quite responsive. Please update this thread too if you find something, this is quite an interesting issue, thanks!

hsqldb update on insert

Does anyone know of a solution to make HSQLDB update columns by calling INSERT. I would like my code to be able to insert, and if there's already data, to update that data. I know MySQl, I believe, has 'ON DUPLICATE KEY UPDATE'. I can't seem to find any recent documentation on this.
A good sample is sometimes better the formal documentation on MERGE statement :)
Sample 1
For a table (MY_TABLE) with tho columns (COL_A and COL_B), where the first column is a primary key:
MERGE INTO MY_TABLE AS t USING (VALUES(?,?)) AS vals(a,b)
ON t.COL_A=vals.a
WHEN MATCHED THEN UPDATE SET t.COL_B=vals.b
WHEN NOT MATCHED THEN INSERT VALUES vals.a, vals.b
Sample 2
Let's add another column (COL_C) to our table:
MERGE INTO MY_TABLE AS t USING (VALUES(?,?,?)) AS vals(a,b,c)
ON t.COL_A=vals.a
WHEN MATCHED THEN UPDATE SET t.COL_B=vals.b, t.COL_C=vals.c
WHEN NOT MATCHED THEN INSERT VALUES vals.a, vals.b, vals.c
Sample 3
Now let's change the primary key to consist of first two columns (COL_A and COL_B):
MERGE INTO MY_TABLE AS t USING (VALUES(?,?,?)) AS vals(a,b,c)
ON t.COL_A=vals.a AND t.COL_B=vals.b
WHEN MATCHED THEN UPDATE SET t.COL_C=vals.c
WHEN NOT MATCHED THEN INSERT VALUES vals.a, vals.b, vals.c
Enjoy!
HSQLDB provides the MERGE statement for this purpose.
http://hsqldb.org/doc/2.0/guide/dataaccess-chapt.html#dac_merge_statement
Alternatively, you can write a short stored procedure to insert, then catch any constraint violation exception and perform an update.
http://hsqldb.org/doc/2.0/guide/sqlroutines-chapt.html#src_psm_handlers
Update: From version 2.3.4 HSQLDB also supports the MySQL syntax for ON DUPLICATE KEY

Subsonic Oracle autoincrement problem

I think this question has been done before, but I don't find a clear answer.
I have migrated SQl Server 2005 database to oracle 11. I am using subsonic 2.1. I have manged to create all the data layer classes, and generates everything well. But the problem turns up when I try to make an insert in the database: Oracle does not have autoincrement in the primary key unless you define a sequence and a trigger. In consequence, Subsonic defines all the Insert methods in the controller with the id column. Is there a way to avoid subsonic not generate Insert methods with the id column, which I am going to generate using a trigger and a sequence?
Thanks a lot
SToledo
UPDATE
I finally did a horrible hack (I feel ashamed) in Subsonic 2.1 source code. I did modify OracleDataProvider to set id-named columns to be autoincrement to true. Then, the template will behave as I expect. I know is a terrible hack, but it works for me.
Thanks for your help guys.
Don't know about Subsonic, but if number of tables is relatively small, you can modify BEFORE-INSERT trigger to disable nullity check:
CREATE OR REPLACE TRIGGER trig_BI
BEFORE INSERT
ON tab_name
FOR EACH ROW
BEGIN
--IF :NEW.key_column IS NULL
--THEN
SELECT tab_seq.NEXTVAL INTO :NEW.key_column FROM DUAL;
--END IF;
END;

Liquibase - uploading many Oracle triggers in one file

I have a number of Oracle triggers stored in a file which we upload to our DB using sqlplus. We want to use liquibase instead to manage this, but I don't really want to split out the triggers into separate files. The file looks like:
create or replace trigger Trig1 ...
...
end Trig1;
/
create or replace trigger Trig2 ...
...
end Trig2;
/
...etc.
I've tried
<sqlFile splitStatements="true" endDelimiter="/" path="triggers.sql">
but it still seems to be trying to split on ';'. If I change splitStatements to false. it then ignores the '/' and includes everything as an invalid single trigger.
Any ideas?
TIA.
I realize this is an old issue and OP has moved on, but for anyone else I ended up finding the answer here: http://forum.liquibase.org/topic/oracle-end-delimiter-issue.
It turns out "endDelimiter" is a regular expression -- this string should be used:
\n/\s*\n|\n/\s*$
I recently got this issue. endDelimiter should be:
endDelimiter="(?m)^/$"
I have a similar problem with Oracle 11g and Liquibase. I get an ORA-00911.
In my db-changelog.xml I point to a sql file where I have triggers. This does not work at all. I have tested the things you said above with /\;
CREATE OR REPLACE TRIGGER ADRESSE_ID_TR
BEFORE INSERT ON ADRESSE
FOR EACH ROW
WHEN (new.ID IS NULL) BEGIN
SELECT adresse_seq.NEXTVAL
INTO :new.ID
FROM dual;
END ADRESSE_ID_TR;\
My workaround is adding a in in db-changelog.xml.
I don't like it because the db-changelog.xml is going to be very large and I want it in the .sql files not in db-changelog.xml.
Another problem is when I generate DDL's with tools like Oracle SQL Developer and paste them in, they don't work. A lot of sql's don't work, probably not supported. I spend a lot of time testing my SQL's and Liquibase with Eclipse to fix the SQL's.
Any tips or will you fix this?
That syntax looks correct. The endDelimiter should be telling it to override the default ; delimiter and use / instead. What version of liquibase are you using? Does it help if you put the \ not by itself?
create or replace trigger Trig1 ...
...
end Trig1; /
create or replace trigger Trig2 ...
...
end Trig2; /
...etc.

Resources