搜索

pgsql零散内容


发布时间: 2022-11-24 18:21:03    浏览次数:46 次

1. Truncate

 语法:truncate table table_name ;

 truncate table用于删除表中的所有行,而不记录单个删除操作;

 速度快,使用的系统资源和事务日志资源更好;

 能针对具有自动递增的字段,做计数重置归零重新计算的作用,只能作用于表;

 

2. union

 语法:

 select column1, colmn2, ... from table1

 union 

 select column1, colmn2, ... from table2

 操作符用于合并两个或多个select语句的结果集;

 union内部的select语句必须拥有相同数量的列,列也必须拥有相似的数据类型;

 每条select语句中列的顺序必须相同;

 

3. union all

 union all操作符合并的结果集,不会允许重复值,如果允许有重复值的话,使用union all;

 规则同上;

 

4.声明表的分布策略

 gp的分布键作用是保证数据能够均匀分布在不同的存储节点上,充分利用并行计算带来的高性能。

 gp包含Hash分布和随机分布。

 hash分布:distributed by(列名)

 随机分布:disrributed by randonly

 在创建表或者修改表定义的时候,必须使用distributed by 来执行分布键,从而使数据均匀的存储在不同的Segment上。

 如果致命的分布键(列名)不是主键,则无法创建(指定的列必须是主键)。

 (1)声明hash分布

 create table 表名(

  id integer primary key, {主键约束}

  name text not null, {非空约束}

  price numeric check(price>0), {检查约束}

  type integer unique {唯一约束}

  ) distributed by(id);

 (2)声明随机分布

 create table 表名(

 id integer primary key, {主键约束,这里就不能在声明主键约束}

 name text not null, {非空约束}

 price numeric check(price>0), {检查约束}

 type integer unique {唯一约束,这里就不能在声明唯一约束}

 ) distributed by randonly; {指定随机分布}

 5.distinct 唯一值

  语法:select col1, distinct col2 from ......

      select distinct col1, col2, col3, ......   from ......

免责声明 pgsql零散内容,资源类别:文本, 浏览次数:46 次, 文件大小:-- , 由本站蜘蛛搜索收录2022-11-24 06:21:03。此页面由程序自动采集,只作交流和学习使用,本站不储存任何资源文件,如有侵权内容请联系我们举报删除, 感谢您对本站的支持。 原文链接:https://www.cnblogs.com/xiao-wang-tong-xue/p/16644267.html