Oracle NoSQL - what does mean : Table exists but definitions do not match - oracle-nosql

I run into this issue:
Caused by: java.lang.IllegalArgumentException:
Error: User error in query:
CREATE TABLE failed for table TEST:
Table exists but definitions do not match
I added 2 new columns in my existing database using console, and added them in table creation statement. It hits the error when I run creating table again.
I checked everything, they all match, (name, type…)

the order of columns matter when you create a table. Did you validate this ? The IF NOT EXISTS in the CREATE TABLE clause checks for the same structure of the table. Please refer the documentation below for more details.https://docs.oracle.com/en/database/other-databases/nosql-database/21.1/sqlreferencefornosql/create-table.html
This inform you that the table that you are trying to create exits but the structure is not the same. It could be useful.
A sample to show the error when order of columns is changed:
sql-> CREATE TABLE IF NOT EXISTS testing_tbl(id INTEGER, firstName STRING,
lastName STRING,
PRIMARY KEY (id));
Statement completed successfully
sql-> CREATE TABLE IF NOT EXISTS testing_tbl(id INTEGER, firstName STRING,
lastName STRING,
PRIMARY KEY (id));
Statement did not require execution
sql-> CREATE TABLE IF NOT EXISTS testing_tbl(id INTEGER, lastName STRING,
firstName STRING,
PRIMARY KEY (id));
Error handling command CREATE TABLE IF NOT EXISTS testing_tbl(id INTEGER,
lastName STRING,
firstName STRING,
PRIMARY KEY (id)): Error: User error in query: CREATE TABLE failed for table testing_tbl: Table exists but definitions do not match

Related

Replace hive table with partition

There is a Hive-table with 2 string columns one partition "cmd_out".
I'm trying to rename all 2 columns ('col1', 'col2'), by using Replace-function:
Alter table 'table_test' replace columns(
'col22' String,
'coll33' String
)
But I receive the following exception:
Partition column name 'cmd_out' conflicts with table columns.
When I include the partition column in query
Alter table 'table_test' replace columns(
'cmd_out' String,
'col22' String,
'coll33' String
)
I receive:
Duplicate column name cmd_out in the table definition
if you want to rename a column, you need to use alter table ... change.
Here is the syntax
alter table mytab change col1 new_col1 string;

Error creating a Oracle NoSQL table with ENUM fields

I have the following error when trying to create this table :
IllegalArgumentException: Error: at (1, 88) Missing closing ')', at line 1:88
Create table TEST (
id String,
fileType ENUM (DOCUMENT,VIDEO),
status ENUM (IN_PROGRESS,PARTIAL_SUCCESS,SUCCEEDED,FAILED,NULL),
primary key (id)
)
I've spent a little time to understand what I was doing wrong, the error message is not clear.
Literal "null" is a reserved word in the query language so it is not supported in that location.
status ENUM (IN_PROGRESS,PARTIAL_SUCCESS,SUCCEEDED,FAILED,NULL),
By the way, We can insert data with null values for the ENUM fields.So, I just create the same table but without including the value NULL
Create table TEST (
id String,
fileType ENUM (DOCUMENT,VIDEO),
status ENUM (IN_PROGRESS,PARTIAL_SUCCESS,SUCCEEDED,FAILED),
primary key (id)
)

Spring H2 created table not found after successful creation

I am using Spring Boot's schema.sql magic to create an in memory H2 database. The script contains the following statements:
create table PERSON
(
ID BIGINT not null primary key,
NAME VARCHAR(255) not null
);
create index IDX_PERSON_NAME on PERSON (NAME);
Upon launch Spring Boo fails with the following exception:
Caused by: org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #2 of URL [file:/D:/git/.../build/resources/main/schema.sql]: create index IDX_PERSON_NAME on PERSON (NAME); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "PERSON" not found; SQL statement:
create index IDX_PERSON_NAME on PERSON (NAME) [42102-200]
How can the statement fail to find the table that was created in the preceding statement?
Simply because NAME is not mentioned as Unique constraint, you have only specified it as NOT NULL constraint
create table PERSON
(
ID BIGINT not null primary key,
NAME VARCHAR(255) not null,
CONSTRAINT Person_Name_Unique UNIQUE (NAME)
);
create index IDX_PERSON_NAME on PERSON (NAME);
Here are the possible reasons,
The schema needs to be mentioned on while referring to table like test_schema.person
Your syntax for creating the index might be wrong. Refer to this link for H2 Syntax,https://www.baeldung.com/spring-yaml

Oracle pushing me ORA-00902: invalid datatype

create table accountDetails(
accountNumber int unique,
customerId int unique,
balance int not null,
password varchar(255) not null,
type varchar(255) not null check(type in ('Savings','Current')),
primary key(accountNumber,customerId) )
create table statusDetails(
customerId int references accountDetails(customerId),
primarykey(customerId))
The last table resulted in an error
The last table resulted in an error
ORA-00902: invalid datatype error happens when we try to define a column using an invalid datatype. It's logical really.
Now, you think you haven't declared a column with an invalid datatype, because you think statusdetails table has only one column, customerid. But if you look at your actual statement you follow that column with this:
primarykey(customerId))
Because you mis-typed primary key Oracle treats that line as an attempt to create a second column. Hence the error, because (customerId) is an invalid datatype. So all you need do is pop in the missing space and Oracle will create the table for you.
create table statusDetails(
customerId int references accountDetails(customerId),
primary key(customerId))
You had a compilation error caused by a simple typo. A key skill for a developer is the ability to turn a cool eye on our own code. I urge you to work on acquiring that skill as soon as you can.
Your second table declaration is all wrong. Try this:
CREATE TABLE statusdetails (
customerid INT,
CONSTRAINT fk_cust FOREIGN KEY ( customerid )
REFERENCES accountdetails ( customerid )
)
Note: using "int" data type maps to a NUMBER(38), which may not be what you want. Use the proper oracle data type names.

alter table statements to enforce entity integrity

He guys I have the following the tables for ORACLE 10g and the problem is i am trying to enforce entity integrity on ALL tables. I have completed the first 4 but the last one is throwing an error. I have used the following code to alter the tables:
ALTER TABLE name ADD CONSTRAINT name PRIMARY KEY (name);
Actor (actorID, lastName, firstName, middleName, suffix, gender, birthDate, deathDate)
Movie (movieID, title, year, company, totalNoms, awardsWon, DVDPrice, discountPrice)
Quote (quoteID, quote)
Role (roleID ,roleName ,gender ,actorID* ,movieID*)
RoleQuote (roleID*, quoteID*)
for the last table (RoleQuote) i have tried
ALTER TABLE name ADD CONSTRAINT name, name PRIMARY KEY (name, name);
but it is throwing this error:
invalid identifier
Can anyone help me thanks the tables have been created without error and they work flawless but the constraint on the last table (RoleQuote)is not working.
ALTER TABLE table_name ADD CONSTRAINT Constraint_name PRIMARY KEY (Field1_name, Field2_name);

Resources