• mysql改为postgresql 语法常见问题


    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');

  • 相关阅读:
    ‘随意’不是个好词,‘用心’才是
    servlet
    tomcat服务器
    http协议
    jdbc(Java数据库连接)
    dbcp和druid(数据库连接池)
    关于GitHub
    冒泡和递归
    python内置函数
    python四
  • 原文地址:https://www.cnblogs.com/xiaokangk/p/14343460.html
Copyright © 2020-2023  润新知