Home > Back-end >  Flyway migration in postgresql?
Flyway migration in postgresql?

Time:12-05

I'm trying to add an entry to Postgresql using such a request

insert into customer (id, email, name, number_telephone) VALUES (public.hibernate_sequence_customer.nextval, '[email protected]' , 'Henry', '89132547898');

, but flyway throws an error

Error: table "hibernate_sequence_customer" is missing in the FROM clause

In the project structure enter image description here

CodePudding user response:

The next value of your sequence is accessed via nextval('public.hibernate_sequence_customer'), not dot notation.

insert into customer (
    id,
    email,
    name,
    number_telephone)
VALUES (
    nextval('public.hibernate_sequence_customer'),
    '[email protected]' ,
    'Henry',
    '89132547898');

but if you define id column as serial, you don't need to call the sequence at all.

create table customer (
    id serial primary key,
    email text,
    name text,
    number_telephone text);

Just skip it in your insert:

insert into customer (
    email,
    name,
    number_telephone)
VALUES (
    '[email protected]' ,
    'Henry',
    '89132547898');

If you later need to refer to the sequence responsible for the id column - to get its current value, for example - you can use currval(pg_get_serial_sequence('customer','id')).

  • Related