zoukankan      html  css  js  c++  java
  • sqlserver 转 postgresql

     pgsql
     1. 没有isnull 用 coalesce
     2. 字符串拼接用 || 
     3. 字符串类型和int类型不会自动转换(用作条件时)
     4. 多行转一列 string_agg(distinct(字段名),'分隔符') distinct是为了去重可以不要
     5. unnest(string_to_array (par_LoadingNos, ','))  //string_to_array 以 , 分隔字符串  unnest 把数据变为一列返回
     6. 没有charindex,用strpos (原字符串,需要查找的)
     7. 没有getdate() 用 LOCALTIMESTAMP(0) 代替 参数指秒以下取几位
     8. 联表更新方法 update a set value = 'test' from b,c where a.b_id = b.id and b.c_id = c.id and a.key = 'test' and c.value = 'test';
     9. 查询表结构 SELECT a.attnum,a.attname AS field,t.typname AS type,a.attlen AS length,a.atttypmod AS lengthvar,a.attnotnull AS notnull
    FROM pg_class c,pg_attribute a,pg_type t
    WHERE c.relname = 'cms_qq' and a.attnum > 0 and a.attrelid = c.oid and a.atttypid = t.oid
    ORDER BY a.attnum;
     10. 创建临时表     create TEMPORARY table 表名 , select * into temp 表名  from  ,函数不能select into  里只能  create TEMPORARY table 表名(...) as select * From .
     11.条件写法: IF 表达试  THEN  ELSIF  表达试  THEN  ELSE  END IF; // IF EXISTS() THEN ....
     12.     1、增加一列ALTER TABLE table_name ADD column_name datatype;
    
     
    
            2、删除一列
            ALTER TABLE table_name DROP column_name;
    
     
    
            3、更改列的数据类型
            ALTER TABLE table_name ALTER column_name TYPE datatype;
    
     
    
            4、表的重命名
            ALTER TABLE table_name RENAME TO new_name;
    
     
    
            5、更改列的名字
            ALTER TABLE table_name RENAME column_name to new_column_name;
    
     
    
            6、字段的not null设置
            ALTER TABLE table_name ALTER column_name {SET|DROP} NOT NULL;
    
     
    
            7、给列添加default
            ALTER TABLE table_name ALTER column_name SET DEFAULT expression;
            
     13. LASTVAL() 方法类型于sqlserver里的@@IDENTITY        
     14. 去两边空格  trim()         
     15. 正则(https://www.cnblogs.com/qiyebao/p/4980648.html)
         1. select * from user where email ~* '^[a-h]'
         2. 'abc' LIKE 'abc'    true
            'abc' LIKE 'a%'     true
            'abc' LIKE '_b_'    true
            'abc' LIKE 'c'      false
            
            'abc' SIMILAR TO 'abc'      true
            'abc' SIMILAR TO 'a'    false
            'abc' SIMILAR TO '%(b|d)%'  true
            'abc' SIMILAR TO '(b|c)%'   false
            
     16. 设置自增列启始值
        ALTER TABLE public.sc_users3
    ALTER COLUMN userid ADD
    GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 2000 MINVALUE 2000 MAXVALUE 9223372036854775807 CACHE 1 ) 
     
      17. INNER JOIN LATERAL与CROSS APPLY
        并且LEFT JOIN LATERAL相同OUTER APPLY
        
      18. 创建索引    CREATE INDEX Form_ASN_QIndex ON Form_ASN (FormID,VendorID);
      
      19. 分页查询 order by lastname limit 5 offset 0;(order by 不是必须的)
      
      20. 输出文字 到输出界面 raise notice 'My name is %, I am a %.', 'Lewis', 'coder';
      
      21. json和jsonb 或 Array 里取值出来 请参考操作符
      
      22. 插入自增列  insert into test (id, info) OVERRIDING SYSTEM VALUE values (1,'test'); 
      
      23.生成GUID需要添加扩展. 以下为一种(还有其它的方式)
       create extension "uuid-ossp" ;
       select uuid_generate_v4() 
    

      

  • 相关阅读:
    Centos7 安装 mysql5.7
    python正则表达式---七七八八
    爬虫之英雄联盟
    爬虫之User-Agent
    爬虫之证书错误
    ubuntu windows双系统 删除Ubuntu后windows系统引导修复
    ubuntu系統桌面重置
    ubuntu安装qtcreator
    win10/ubuntu双系统----ubuntu有线无线都不能上网
    pyenv 安装
  • 原文地址:https://www.cnblogs.com/2eggs/p/15154394.html
Copyright © 2011-2022 走看看