postgresql - Initializing an Empty Table using schema.sql in Spring Boot -


i use table in postgres providing authorization in springboot web app connects postgres database. want initialize table default admin entry if table empty. doing within schema.sql file here code have attempted far:

create table if not exists public.jdbcauth (     username varchar(32),     password varchar(32) default null,     role varchar(32) default null,     enabled int default 0,     primary key(username) );  if exists (select 1 public.jdbcauth)     insert public.jdbcauth (username, password, role, enabled) values ('admin', 'admin', 'admin', '1'); 

this fails following error:

caused by: org.springframework.beans.factory.beancreationexception:  error creating bean name 'datasourceinitializer': invocation of init method failed; nested exception org.springframework.jdbc.datasource.init.scriptstatementfailedexception: failed execute sql script statement #2 of resource url [file:/home/balajeerc/projects/igvds_webapp/src/main/resources/schema.sql]: if exists (select 1 public.jdbcauth) insert public.jdbcauth (username, password, role, enabled) values ('admin', 'admin', 'admin', '1');  nested exception org.postgresql.util.psqlexception:  error: syntax error @ or near "if" 

what doing wrong?

don't need "then"?

if exists (select 1 public.jdbcauth)     insert public.jdbcauth (username, password, role, enabled) values ('admin', 'admin', 'admin', '1'); 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -