I have DDL for my PostgreSQL database. One of the columns in the table is of type VARCHAR[]. H2 fails to create this table, even if the database is running in PosgtreSQL compatibility mode (url: jdbc:h2:mem:user-management;MODE=PostgreSQL)
Simplified DDL:
create table "users" (
"uuid" VARCHAR NOT NULL PRIMARY KEY,
"roles" VARCHAR[] NOT NULL
);
Is there any data type that is compatible between H2 and PostgreSQL and is actually a varchar array? Thanks!
It is possible to use array here, it's worked for me in h2 postgre mode.
create table "users" (
"uuid" VARCHAR NOT NULL PRIMARY KEY,
"roles" varchar array
);
Related
The problem that I can see is that the table is created with the name 'article' and the query is done with ARTICLE in capital letter. I tried to change the application.properties file to this:
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL;NON_KEYWORDS=USER;IGNORECASE=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE;DATABASE_TO_LOWER=TRUE
but it doesn't help the problem.
Here is some output from the console that demonstrate the table has been created:
Hibernate: create table "article" ("id" bigint generated by default as identity, "content" clob, "language" integer, "last_edited" timestamp, "published" timestamp, "title" varchar(255), "image_id" bigint, "user_id" bigint not null, primary key ("id"))
and later this pops up:
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "ARTICLE" not found; SQL statement: select * from Article where language=? ORDER BY published desc
I tried to name the table in uppercase letter with
DATABASE_TO_LOWER=FALSE, DATABASE_TO_UPPER=TRUE;
and it didn't help either.
What could I try next?
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
I'm trying to retrieve FK of a given table with JDBC metadata.
For that, I'm using the "getImportedKeys" function.
For my table 'cash_mgt_strategy', it give in resultset:
PKTABLE_CAT : 'HAWK'
PKTABLE_SCHEM : 'dbo'
PKTABLE_NAME : 'fx_execution_strategy_policy'
PKCOLUMN_NAME : 'fx_execution_strategy_policy_id'
FKTABLE_CAT : 'HAWK'
FKTABLE_SCHEM : 'dbo'
FKTABLE_NAME : 'cash_mgt_strategy'
FKCOLUMN_NAME : 'fx_est_execution_strategy_policy'
KEY_SEQ : '1'
UPDATE_RULE : '1'
DELETE_RULE : '1'
FK_NAME : 'fk_fx_est_execution_strategy_policy'
PK_NAME : 'cash_mgt_s_1283127861'
DEFERRABILITY : '7'
The problem is that the "FKCOLUMN_NAME : 'fx_est_execution_strategy_policy'" is not a real column of my table, but it seems to be truncated? (missing "_id" at the end)
When using an official Sybase sql client (Sybase Workspace), displaying the DDL of the table give for this constraint / foreign key:
ALTER TABLE dbo.cash_mgt_strategy ADD CONSTRAINT fk_fx_est_execution_strategy_policy FOREIGN KEY (fx_est_execution_strategy_policy_id)
REFERENCES HAWK.dbo.fx_execution_strategy_policy (fx_execution_strategy_policy_id)
So I'm wondering how to retrieve the full FKCOLUMN_NAME ?
Note that I'm using jconnect 6.0.
I've tested with jconnect 7.0, same problem.
Thanks
You haven't provided your ASE version so I'm going to assume the following:
dataserver was running ASE 12.x at some point (descriptor names limited to 30 characters)
dataserver was upgraded to ASE 15.x/16.x (descriptor names extended to 255 characters)
DBA failed to upgrade/update the sp_jdbc* procs after the upgrade to ASE 15.x/16.x (hence the old ASE 12.x version of the procs - descriptors limited to 30 characters - are still in use in the dataserver)
If the above is true then sp_version should show the older versions of the jdbc procs running in the dataserver.
The (obvious) solution would be to have the DBA load the latest version of the jdbc stored procs (typically found under ${SYBASE}/jConnect*/sp).
NOTE: Probably wouldn't hurt to have the DBA review the output from sp_version to see if there are any other upgrade scripts that need to be loaded (eg, installmodel, installsecurity, installcommit, etc).
Ok, so I've done some search on my DB server and I've found the code of stored proc sp_jdbc_importkey. In this code can see:
create table #jfkey_res(
PKTABLE_CAT varchar(32) null,
PKTABLE_SCHEM varchar(32) null,
PKTABLE_NAME varchar(257) null,
PKCOLUMN_NAME varchar(257) null,
FKTABLE_CAT varchar(32) null,
FKTABLE_SCHEM varchar(32) null,
FKTABLE_NAME varchar(257) null,
FKCOLUMN_NAME varchar(257) null,
KEY_SEQ smallint,
UPDATE_RULE smallint,
DELETE_RULE smallint,
FK_NAME varchar(257),
PK_NAME varchar(257) null)
create table #jpkeys(seq int, keys varchar(32) null)
create table #jfkeys(seq int, keys varchar(32) null)
The temporary tables #jpkeys and #jfkeys used to store the column names (for PK and FK) are typed with varchar(32) instead of 257!!
Need to search how to patch / update theses stored proc now.
I am trying to use the NullDB database adapter to create/run specs for an external database. As I dont want to query the external database for the specs I want to use NullDB instead.
The Problem is: I created a seperate schema.rb file that should be used by nulldb, set nulldb as adapter and the schema.rb path in my config for the test env, but, my models dont have columns, therefore methods like name= are also failing.
NullDb reads out the schema correct and also creates tables with the columns.
NullDBNamespace::Product.columns
(4.2ms) DROP TABLE "products"
(9.8ms) CREATE TABLE "products" ("id" serial primary key, "products_id" integer, "products_model" integer, "products_master" integer, "manufacturers_id" integer, "products_tax_class_id" integer, "products_quantity" integer, "products_evp" decimal(16,8), "products_ean" character varying)
(3.1ms) DROP TABLE "descriptions"
(7.1ms) CREATE TABLE "descriptions" ("id" serial primary key, "products_id" integer, "language_id" integer, "products_name" character varying, "products_description" text)
(3.1ms) DROP TABLE "languages"
(5.9ms) CREATE TABLE "languages" ("id" serial primary key, "languages_id" integer, "name" character varying, "code" character varying)
but I get
NullDBNamespace::Product.columns
=> []
also there are no tables for the connection:
NullDBNamespace::Product.connection.tables
=> ["schema_info"]
Does anybody has an idea?
What can I do if I need to create entity for
a table in production DB (Oracle 10g) with composite primary key.
For example:
[CODE]
CREATE TABLE TACCOUNT
(
BRANCHID NUMBER(3) NOT NULL,
ACC VARCHAR2(18 BYTE) NOT NULL,
DATE_OPEN DATE NOT NULL,
DATE_CLOSE DATE,
NOTE VARCHAR2(38 BYTE)
);
CREATE UNIQUE INDEX PK_TACCOUNT ON TACCOUNT
(BRANCHID, ACC);
I don't want to change the structure of this table.
Is it possible to create an "id" field using roo commands?
I use Spring Roo 1.0.2.RELEASE [rev 638]