zoukankan      html  css  js  c++  java
  • 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');

  • 相关阅读:
    理解JAVA常量池
    java存储位置经典例子
    java通过句柄访问对象
    常用排序算法小结
    String,StringBuffer与StringBuilder的区别
    BGP
    BGP
    python编码问题实例
    从一段代码学习二叉树
    二叉树学习笔记--先序遍历
  • 原文地址:https://www.cnblogs.com/xiaokangk/p/14343460.html
Copyright © 2011-2022 走看看