As titled, I am trying to migrate my h2 database to a postgres docker.
I made a dump of my h2 database using the command
SCRIPT TO 'fileName'
I then copied the file to my docker through the docker cp command. After that, I created a new database, and I tried launching
psql realdb < myfile.sql
which gave me an enourmous serie of errors, including:
ERROR: syntax error at or near "."
LINE 1: ...TER TABLE PUBLIC.FILE_RECORD ADD CONSTRAINT PUBLIC.CONSTRAIN...
^
ERROR: syntax error at or near "CACHED"
LINE 1: CREATE CACHED TABLE PUBLIC.NODE_EVENT(
^
ERROR: syntax error at or near "."
LINE 1: ...LTER TABLE PUBLIC.NODE_EVENT ADD CONSTRAINT PUBLIC.CONSTRAIN...
^
ERROR: relation "public.node_event" does not exist
LINE 1: INSERT INTO PUBLIC.NODE_EVENT(ID, DAY, HOUR, MINUTE, MONTH, ...
^
NOTICE: table "system_lob_stream" does not exist, skipping
DROP TABLE
ERROR: syntax error at or near "CALL"
LINE 1: CALL SYSTEM_COMBINE_BLOB(-1);
So I decided I would try dumping the database as a csv file, which perhaps a more standard approach, using the command
call CSVWRITE( '/home/lee/test.csv' , 'SELECT * FROM PORT' )
which seems to work for just one table at time. Is there a way to export all tables at once? How would I import them into postgres docker?
Is there a better way to do all of this?
This is my application.config
spring.datasource.url=jdbc:h2:/tmp/ossdb:testdb;MODE=PostgreSQL
spring.datasource.username=admin
spring.datasource.password=admin
spring.datasource.platform=postgresql
Related
Trying to execute the following code :
this.getSessionFactory().getCurrentSession()
.createNativeQuery("SET app.variable = :variable")
.setParameter("variable","variableValue")
.executeUpdate();
It is giving me the following error :
org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1"
Position: 26
I'm not sure if this is a bug in JDBC or PostgreSQL.
It seems not a PostgreSQL issue as when I use the DBeaver using bind variables the query works fine.
Tried the same query by creating a prepared statement as well and the Result was same.
The SQL statement SET accepts no parameters. Only SELECT, VALUES, INSERT, UPDATE, DELETE and MERGE do.
well my problem is that i need to import data to a postgres table through java from a csv file, the thing is when i import the data with PGadmin4 it is imported without errors, however when i
execute this sql statement with java COPY account FROM 'path/account.csv' DELIMITER ',' QUOTE '"' HEADER CSV an exception occures stating this :
was aborted: ERROR: date/time field value out of range: "24/3/1995"
IndiceĀ : Perhaps you need a different "datestyle" setting.
i have checked the datetime and it's dmy
I am using SQuirelL client to connect to MariaDB. My OS is Ubuntu. I have downloaded the Mariadb driver (mariadb-java-client-1.5.2.jar) to the proper location and linked it in the SQuirelL client. I have setup a database, and am able to create tables in it.
But things go south when i try creating any object where i use a DELIMITER. I have even tried with the mysql driver, mysql-connector-java-5.1.38.jar. but same error.
this is my SQL -
DELIMITER //
CREATE FUNCTION FortyTwo() RETURNS TINYINT DETERMINISTIC
BEGIN
DECLARE x TINYINT;
SET x = 42;
RETURN x;
END
//
DELIMITER ;
and this is the error -
Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DELIMITER //
CREATE FUNCTION FortyTwo() RETURNS TINYINT DETERMINISTIC
BEGIN
DE' at line 1
Query is : DELIMITER //
CREATE FUNCTION FortyTwo() RETURNS TINYINT DETERMINISTIC
BEGIN
DECLARE x TINYINT
SQLState: 42000
ErrorCode: 1064
Error occurred in:
DELIMITER //
CREATE FUNCTION FortyTwo() RETURNS TINYINT DETERMINISTIC
BEGIN
DECLARE x TINYINT
I will greatly appreciate any help ! Thanks
DELIMITER is not a valid MariaDB SQL command.
Look at the documentation. You won't find it there.
DELIMITER is a MySQL Client command:
mysql> help
List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
...
delimiter (\d) Set statement delimiter.
...
You generally don't need delimiters, since you only execute one command at a time when using JDBC.
They can be batched if needed for performance, but they should still be submitted to the JDBC driver one at a time.
I want to write script for create database with tables in PostgreSQL.
I created deploy_db.bat:
#echo off
"C:\Program Files\PostgreSQL\9.4\bin\psql.exe" -h localhost -p 5433 -U postgres -d postgres -f run_main.sql
pause
my run_main.sql:
BEGIN;
\i create_db.sql
\i tableA.sql
COMMIT;
create_db.sql:
CREATE DATABASE test;
DROP SCHEMA IF EXISTS test CASCADE;
CREATE SCHEMA test
AUTHORIZATION postgres;
tableA.sql:
CREATE TABLE test.tableA(
id serial PRIMARY KEY,
name text,
age INTEGER
);
So, I run deploy_db.bat and see:
BEGIN
psql:create_db.sql:1: ERROR: CREATE DATABASE cannot run inside a transaction block
psql:create_db.sql:3: ERROR: current transaction is aborted, commands ignored until end of transaction block
ROLLBACK
But, Why? How can resolved it?
You issued BEGIN which started a transaction, then CREATE DATABASE which produced the error message because you ran it inside the transaction.
You could just move the CREATE DATABASE statement before the BEGIN, that would get rid of the error message.
But reading your SQL script I suspect that you want to create the new schema and table in the newly created database, which is not what will happen with your script. Rather, the schema and the table will be created in the database postgres.
To change that, your script should look like this:
CREATE DATABASE test;
-- connect to that database
\connect test
-- now create your schema and your table
CREATE SCHEMA ...
CREATE TABLE ...
I am trying to execute a whole directory of .SQL files in Java.
I'm struggling to execute a stored procedure. I have found this so far (the most helpful) including a dead link, sadly. I have downloaded liquibase also, but I cannot figure out how I should use it for this purpose.
In my current code, I split the files including procedures into different statements:
(Statements split in a Vector[String] and executed in a for loop)
Example:
//File f;
//Statement st;
Vector<String> vProcedure = getProcedureStatements(f, Charset.defaultCharset(), "//");
for (Iterator<String> itr = vProcedure.iterator(); itr.hasNext();)
st.execute(itr.next());
System.out.println(f.getName() + " - done executing.");
The Vector contains the four elements (see SQL-Code #SPLIT x).
DROP PROCEDURE IF EXISTS `Add_Position`; #SPLIT 1
DELIMITER // #SPLIT 2
CREATE PROCEDURE `Add_Position`
(
IN iO_ID INT,
IN iCID INT,
IN iWID INT,
IN iA INT
)
BEGIN
#statements;
END
// #SPLIT 3
DELIMITER ; #SPLIT 4
Result when trying to execute #SPLIT 2:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER //' at line 1
Q: Could anyone tell me if there's a exteral library I could use, or how liquibase does work ? I can't get it to work the JDBC-way.
The statement DELIMITER \\ is not actually SQL - it is a command that is interpreted by the mysql command-line tool (and possibly also their GUI tool), but if you pass it straight to the execution engine, you will get this syntax error.
Unfortunately, Liquibase uses ; as the default statement separator, so it is difficult to get this sort of thing to work using SQL files and Liquibase. I have put in a pull request to allow setting the delimiter from the Liquibase command line - see https://github.com/liquibase/liquibase/pull/361.