HSQLDB error while creating a table that contains DOUBLE type columns - hsqldb

I am using HSQLDB for my integration tests to create tables in-memory. When i run my test, it fails to create the table for the entity classes that have double values. I get the below mentioned exception
2603 [Datastore main ERROR] Error thrown
executing CREATE TABLE "simple"."SimpleObject"
(
"id" BIGINT GENERATED BY DEFAULT AS IDENTITY,
"name" VARCHAR(40) NOT NULL,
"notes" VARCHAR(4000) NULL,
"salary" DOUBLE(4000) NULL,
"version" TIMESTAMP NOT NULL,
CONSTRAINT "SimpleObject_PK" PRIMARY KEY ("id")
) : unexpected token: ( : line: 6
java.sql.SQLSyntaxErrorException: unexpected token: ( : line: 6
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.execute(Unknown Source)
But when i change the value to BigDecimal, it works. But I am really eager to find why DOUBLE have issues. Any help is much appreciated.

The reason is: it is not allowed by the SQL standard. The DOUBLE is the type for approximate floating point numbers. It cannot have a maximum length, like the VARCHAR type. Just use "salary" DOUBLE NULL.

Related

Cockroachdb varchar column length isn't flexible

I have a spring boot application that connects to Cockroachdb. I have the following script in my flyway using which the table gets created:
CREATE TABLE IF NOT EXISTS sample_table (
name varchar,
groups varchar,
PRIMARY KEY (name));
The application starts fine, but whenever there is a value for the 'groups' column that is greater than 255 length, I get an error :
Caused by: org.postgresql.util.PSQLException: ERROR: value too long for type VARCHAR(255)
In the sql script, I have mentioned the column 'groups' as 'varchar' which should not restrict the length so I am not sure why am I getting this error.
There isn't an implicit default limit on varchar in CockroachDB. This error indicates that the groups column was initialized with the type varchar(255) when the table was created. Running SHOW CREATE TABLE sample_table; should confirm this.
It's possible that something unexpected is going on in the flyway and the table is not being created how you want it to be created.

SQL Server 2019 ProgrammingError: Incorrect syntax near 'AUTO_INCREMENT' [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm trying to figure out why I'm getting this error and how to solve it.
The code:
CREATE TABLE sqlalchemy_generic_types
(
'No.' INT NOT NULL AUTO_INCREMENT,
'Object Name' VARCHAR(25) NOT NULL,
'Description' VARCHAR(100) NOT NULL,
PRIMARY KEY('No.')
);
The error:
(pyodbc.ProgrammingError) ('42000', "[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near 'AUTO_INCREMENT'. (102) (SQLExecDirectW)")
[SQL: /* Creating a table */
CREATE TABLE sqlalchemy_generic_types (
'No.' INT NOT NULL AUTO_INCREMENT,
'Object Name' VARCHAR(25) NOT NULL,
'Description' VARCHAR(100) NOT NULL,
PRIMARY KEY('No.')
);]
(Background on this error at: http://sqlalche.me/e/13/f405)
SQL Server doesn't support auto-increment. Nor does SQL Server -- or any other database -- support single quotes for column names (as far as I know).
I would recommend writing the statement as:
CREATE TABLE sqlalchemy_generic_types (
sqlalchemy_generic_type_id INT IDENTITY(1, 1) PRIMARY KEY,
ObjectName VARCHAR(25) NOT NULL,
Description VARCHAR(100) NOT NULL
);
Note the changes:
IDENTITY() is assigns an increasing value to the id.
The id is given a meaningful name.
The space is removed from ObjectName, so the name does not need to be escaped.
No escape characters are needed to define the table.
You need to provide the double quotes for column names if they contain special characters or spaces.
Auto_increment? -- you must be looking for identity(1,1)
You can use following query:
CREATE TABLE sqlalchemy_generic_types (
"No." INT NOT NULL identity(1,1),
"Object Name" VARCHAR(25) NOT NULL,
"Description" VARCHAR(100) NOT NULL,
PRIMARY KEY("No.")
);
Db<>fiddle

Oracle SQL - Table Create Issue

i am currently trying to create a person table that allows a person to be either a client or a staff member. Currently this is my code :-
Create Or Replace Type Person As OBJECT
(
person_id number(5) not null,
firstname varchar2(15) not null,
surname varchar2(15) not null,
address1 varchar2(70) not null,
address2 varchar2(70),
address3 varchar2(70),
postcode varchar2(9) not null
);
/
Create Or Replace Type Client Under Person
(
marital_status varchar2(10),
no_of_children number(2)
);
/
Create Or Replace Type Staff Under Person
(
job_title varchar2(15) not null,
salary number(4,2) not null,
manager_id number(5) not null
);
/
Create Table Person Of Person
(
person_id Primary Key
);
The object types all compile but when it goes to create the table i get the following error:-
SQL Error: ORA-00902: invalid datatype
00902. 00000 - "invalid datatype"
what is causing this error to occur and what can be done to rectify it. Any help is greatly appreciated.
********EDIT**********
I have changed the name of the table to person_tbl and still get the same error. For some reason, this error now appears in the compiler log:-
Error: PL/SQL: Compilation unit analysis terminated
Error(1,18): PLS-00905: object [ConnectionName].PERSON is invalid
I have no idea why it isn't letting me use the Person type as I have triede this method before successfully.
Don't know, why you get these error. You should get the error
00955. 00000 - "name is already used by an existing object"
when trying to create a table with the same name as a type.
Try
Create Table Persons Of Person
(
person_id Primary Key
);
You have a few problems. As #tonirush mentioned, you can't have more than one object in a database with the same name.
Additionally, the person type is compiling with errors (specifically PLS-00218: a variable declared NOT NULL must have an initialization assignment). Until you resolve these errors, you can't build an object table based on the object.
Your subtypes also have compilation errors: PLS-00590: attempting to create a subtype UNDER a FINAL type, but that's not relevant to the inability to create the object table.
As a footnote, the word "object" in this answer (and in Oracle databases, in general) is overloaded. In the first paragraph, I'm speaking of "database objects", which is pretty much anything that is created in the database with a create command. For the rest I'm speaking of "object types" which are object created by create type ... object specifically.

error with parenthesis on pgSQL

using phpPgAdmin, I've tried to create a table in my database. But am getting an error after it has generated its code.
SQL error:
ERROR: syntax error at or near "(" at character 91
CREATE TABLE "public"."main_products_common_dimensions" ("id" SERIAL, "product_id" integer(3) NOT NULL, "h_ft" character varying(15), "h_in" character varying(15), "w_ft" character varying(15), PRIMARY KEY ("id")) WITHOUT OIDS
What could be wrong with the parenthesis?
The problem - you cannot specify precision for integer type, so integer(3) is invalid type. Use numeric(3) or simple integer.
There is no integer(3): postgresql integer is always 4 bytes, signed.

error on table creation using phpPgAdmin

I've been trying to grapple with phpPgAdmin and am having difficulties. when trying to use the automated tool to create a table, I get the following error:
SQL error:
ERROR: syntax error at or near "(" at character 96
In statement:
CREATE TABLE "public"."business_secondary_category" ("id" SERIAL, "primary_category_id" integer(10) DEFAULT NULL, "secondary_category" character varying(150) DEFAULT NULL, PRIMARY KEY ("id")) WITHOUT OIDS
This is how I set it up:
I can't figure out what I've done wrong. Link to character.
Try taking out the length specification for the primary_category_id column, postgresql doesn't support the type integer(10), only integer (aka int4)