Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switching from H2 to PostgreSQL with spring boot

I have a spring boot application working fine on a H2 DB. If I want to switch to postgresQL I get errors.

spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres

Errors:

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "drop table if exists 
user cascade" via JDBC Statement
...
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "user"
...
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table user (id int8 not null, active int4 not null, first_name varchar(255), last_name varchar(255), password varchar(255), role varchar(255), username varchar(255), primary key (id))" via JDBC Statement
like image 215
Java Avatar asked Oct 28 '25 10:10

Java


1 Answers

I think this is because user is a reserved word in PostrgeSQL.

In order to create a table with such name, try quote it (that is, create table "user"...)

Enclosing all the objects' names in 'ANSI quotes' is generally a good idea if you want an interoperability between different databases.

like image 130
Ivan Ponomarev Avatar answered Oct 30 '25 01:10

Ivan Ponomarev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!