pgsql零散内容
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 ......
6.
7、取日期函数
select date_trunc('year',now()) --取年初 select date_trunc('month',now()) --取月初 select date_trunc('day',now()) --取当日日期 select date_part('year',now()) --取年字段 select date_part('months',now()) --取月字段 select date_part('days',now()) --取日字段 select now()+interval'-1 weeks' --上周 select extract(year from now()) from rk --从now()字段中提取年份 select extract(month from now()) from rk --从now()字段中提取月份 select extract(day from now()) from rk --从now()字段中提取日 select extract(hour from now()) from rk --从now()字段中提取时 select extract(minute from now()) from rk --从now()字段中提取分 select extract(second from now()) from rk --从now()字段中提取秒
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现