how to fix liquibase can not create index on oracle - oracle

databaseChangeLog:
- preConditions:
- changeSet:
id: 8
author: myname
context: context
changes:
- createIndex:
tableName: table_name
indexname: index_name
columns:
- column:
name: column_1
Get an error:
DatabaseException: ORA-00953: missing or invalid index name
[Failed SQL: CREATE INDEX ON SYSTEM.CABLEMODEMTERMINATIONSYSTEM(KMA_ID)]

The problem is indexname, it should be indexName (upper-case N).

Related

Tests fail to run with H2 database on Micronaut project with Flyway migrations

I've got a unit test suite in a Micronaut 2.0.3 project that's supposed to run on an H2 DB. Since I started using Flyway for my DB migrations, I'm getting an error coming from H2 being unable to run the migrations.
The error is
Bean definition [javax.sql.DataSource] could not be loaded: Migration V1__schema.sql failed
-------------------------------
SQL State : 42001
Error Code : 42001
Message : Syntax error in SQL statement "CREATE DATABASE[*] IF NOT EXISTS MY_DB"; expected "OR, FORCE, VIEW, ALIAS, SEQUENCE, USER, TRIGGER, ROLE, SCHEMA, CONSTANT, DOMAIN, TYPE, DATATYPE, AGGREGATE, LINKED, MEMORY, CACHED, LOCAL, GLOBAL, TEMP, TEMPORARY, TABLE, SYNONYM, PRIMARY, UNIQUE, HASH, SPATIAL, INDEX"; SQL statement:
CREATE DATABASE if not exists my_db [42001-200]
Location : db/migration/V1__schema.sql (/somelocation/build/resources/main/db/migration/V1__schema.sql)
Line : 1
Statement : CREATE DATABASE if not exists my_db
io.micronaut.context.exceptions.BeanInstantiationException: Bean definition [javax.sql.DataSource] could not be loaded: Migration V1__schema.sql failed
-------------------------------
My application.yml is configured to point at a MariaDB instance in Azure like so:
micronaut:
application:
name: myapp
server:
context-path: /myapp/api
cors:
enabled: true
endpoints:
all:
enabled: true
sensitive: false
datasources:
default:
url: jdbc:mariadb://${ENV_DB_HOST_PORT:myurl.mariadb.database.azure.com}:${ENV_DB_PORT:3306}/${ENV_DB_SCHEMA:my_db}?useSSL=${ENV_DB_USE_SSL:true}&useUnicode=true&serverTimezone=Europe/London&autoReconnect=true
driverClassName: org.mariadb.jdbc.Driver
username: myusername
password: mypassword
dialect: MYSQL
allow-pool-suspension: false
connection-test-query: SELECT 1
connection-timeout: 30000
max-lifetime: 60000
maximum-pool-size: 10
minimum-idle: 1
flyway:
datasources:
default:
enabled: true
But my application-test.yml points at the H2 DB for testing purposes:
datasources:
default:
url: jdbc:h2:mem:devDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
driverClassName: org.h2.Driver
username: sa
password: ''
jpa:
default:
properties:
hibernate:
hbm2ddl:
auto: update
And my migration file V1__schema.sql looks like the following:
CREATE DATABASE if not exists my_db;
use my_db;
DROP TABLE IF EXISTS `preset`;
CREATE TABLE `preset` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`preset_name` varchar(30) NOT NULL,
`preset_value` varchar(4000) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `note`;
CREATE TABLE `note` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`code` varchar(30) NOT NULL,
`text` varchar(4000) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
The error is pretty much self explanatory
Message : Syntax error in SQL statement "CREATE DATABASE[*] IF NOT EXISTS MY_DB";
CREATE DATABASE if not exists my_db;
According to H2 commands, CREATE DATABASE is not a valid command for H2. You probably need the command CREATE SCHEMA if not exists my_db;

Liquibase 'addCheckConstraint' for ENUM colum in Oracle DB allows any character

I have a ENUM column and I am using liquibase addCheckConstraint to allow only ENUM values. However, addCheckConstraint doesnt work and allows any value. My yaml changelog looks as follows:
- changeSet:
id: 1565352995028-1
author: Zafrullah Syed
changes:
- createTable:
columns:
- column:
constraints:
primaryKey: true
name: ID
type: NUMBER(19, 0)
- column:
name: STATUS_ENUM
type: VARCHAR2(10 CHAR)
tableName: BOOKING
- addCheckConstraint:
constraintBody: STATUS_ENUM IN ('ERROR', 'CONFIRMED', 'QUEUED', 'REJECTED')
constraintName: enumcheck
tableName: SOME_TABLE
I am Using Oracle db.
If I try to run a sql query, then constraint works well:
ALTER TABLE SOME_TABLE
ADD CONSTRAINT enumcheck CHECK (status_enum IN ('ERROR', 'CONFIRMED', 'QUEUED', 'REJECTED'));
I tried to add another enableCheckConstraint to enable the existing check constraint but nothing seems to work.
addCheckConstraint is accessible only for the pro version, do you have it?

How to write insert comment for complex array<struct<...>> type in hive?

Table Structure:
CREATE TABLE IF NOT EXISTS test.test_complex_alter(
`id` STRING,
`items` array<struct<
quantity: INT,
articleData:struct<subsysNumber:string>,
pickedReason:string>>
) STORED AS ORC;
How to INSERT data into this complex table using INSERT Query?
Answer to the OP:
Create a dummy table with 1 row ( schema doesn't matter). Let's call it dummy.
Run the below query to insert 1 row into your test.test_complex_alter table:
INSERT INTO TABLE test.test_complex_alter SELECT "id1", array(named_struct('quantity',20, 'articleData', named_struct('subsysNumber', 'subsys1'), 'pickedReason', 'reason1'),named_struct('quantity',30, 'articleData', named_struct('subsysNumber', 'subsys2'), 'pickedReason', 'reason2')) from dummy;
Structure of the array(2nd col):
array(named_struct(n1,v1,..,nn,vn),...,named_struct(n1,v1,..,nn,vn))
Results:
hive> select * from test100.test_complex_alter;
OK
test_complex_alter.id test_complex_alter.items
id1 [{"quantity":20,"articleData":{"subsysNumber":"subsys1"},"pickedReason":"reason1"},{"quantity":30,"articleData":{"subsysNumber":"subsys2"},"pickedReason":"reason2"}]
Ref:
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF -> "Complex Type Constructors"

create index in oracle db 11.2.0.4 connection gets terminated

I tried to create index in oracle db with the below create index
create INDEX index_name ON table_name (column_name)
INDEXTYPE IS "CTXSYS"."CONTEXT";
after 30 secs i am getting the below error
Error starting at line : 5 in command -
create INDEX index_name ON table_name (column_name)
INDEXTYPE IS "CTXSYS"."CONTEXT"
Error report -
SQL Error: No more data to read from socket

Inner query not throwing error in postgres

There is a scenario in which we are retrieving some result from inner query and using the result to perform some operation
create table test1(key integer,value varchar)
insert into test1 values(1,'value 1');
insert into test1 values(2,'value 2');
insert into test1 values(3,'value 3');
second table as
create table test2(key1 integer, valuein varchar);
insert into test2 values (2,'value inside is 2');
insert into test2 values (4,'value inside is 4');
insert into test2 values (5,'value inside is 5');
the below query is giving result but in my view it should give an error
select * from test1 where key in
(select key from test2)
because key column does not exist in test2 table.
but it is giving result in postgres
but when run in oracle it is giving error as
ORA-00904: "KEY": invalid identifier
00904. 00000 - "%s: invalid identifier"
This is the correct behavior as specified in the SQL standard. The inner query has access to all columns of the outer query - and because test1 has a column named key (which, btw is a horrible name for a column) the inner select is valid.
See these discussions on the Postgres mailing list:
http://postgresql.nabble.com/BUG-13336-Unexpected-result-from-invalid-query-td5850684.html

Resources