每天都在进步,说明你有上进心

如果你记忆力差,那可以多写来弥补

springboot引入postgresql 

①pom引入依赖
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1212</version>
</dependency>

②yml文件
spring:
datasource:
url: jdbc:postgresql://192.168.10.223:5866/highgo(数据库名称)?useSSL=false&currentSchema=pipe_network
name: dev
username: highgo
password: abcd=1234
# 使用druid数据源
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: org.postgresql.Driver

常见问题(当然很多问题都是基本问题,只是刚接触新手而已)

1.org.postgresql.util.PSQLException: ERROR: relation "auth_user" does not exist

  postgresql-> 默认连接使用的是highgo数据库的public 模式

  jdbc:postgresql://localhost:5432/highgo

  postgresql-9.3 及以前的版本指定方式

  spring.datasource.url=jdbc:postgresql://localhost:5432/highgo?searchpath=newschema

  postgresql-9.4及以后的版本指定方式

  spring.datasource.url=jdbc:postgresql://localhost:5432/highgo?currentSchema=newschema

 

 

 

  资料来源:https://blog.csdn.net/qq_32719215/article/details/104943498

 2.mysql中的find_in_set 用 Any替代

  mysql:

    SELECT * from table where find_in_set(id,id列以逗号分隔的字符串列)

  postgresql:

    SELECT * from table where  id = ANY(string_to_array(id列以逗号分隔的字符串,','))

 

 3.mysql中的GROUP_CONCAT用 string_agg替代

  mysql:

     select GROUP_CONCAT(brand) from ca_car

 postgresql:
    select string_agg(brand,',') from ca_car

 4.创建自增长主键

  DROP SEQUENCE if EXISTS "pipe_network"."psm_monitor_point_id_seq";

  CREATE SEQUENCE "pipe_network"."psm_monitor_point_id_seq"
  INCREMENT 1
  MINVALUE 1
  MAXVALUE 9223372036854775807
  START 1
  CACHE 1;

  ('pipe_network.psm_point_data_id_seq'::regclass)

create SEQUENCE seq_ds_user_apply_basic_id;
ALTER table ds_user_apply_basic ALTER COLUMN id set default nextval('seq_ds_user_apply_basic_id'::regclass);

 5.修改序列

-- 序列重置到1000
alter sequence sequence_name restart with 1000
-- 验证
SELECT nextval('sequence_name');

posted on 2021-01-29 10:18  代码中透露着杀气  阅读(1507)  评论(0编辑  收藏  举报

如果你记忆力差,那可以多写来弥补