postgresSql-基础入门(待续...)

创建普通的数据库

create database db_test;
--创建数据库的时候指定其所有者为postgres,并且指定其编码格式为utf-8
create database db_test1 with owner =postgres encoding='utf-8'
--修改数据库的名称
alter database db_test1 rename to db_test3
--删除数据库
drop database db_test3

数值类型

整数类型

  • Smallint 小范围整数,取值范围:-32768—32767
  • Int(integer) 普通大小整数 -2147483648-2147483647

任意精度浮点数类型

  • Real 6位十进制数字精度
  • Numberic(m,n) 任意精度类型

使用numberic会产生四舍五入的,
例如number(4,2)
100.23没问题、1000.23就会报错,超出精度、100.235不会报错,但是存在数据库中就变成了100.24;

  • 注意:小数不占有长度numeric(5,2),表示长度是5 ,即小数位+整数位=5

时间与日期类型

字符串类型

运算符

1是否在1和2之间,3是否在1和2之间

2是否在1和2组成的集合之中、2是否在3和4组成的集合之中,2是否不在3和4组成的集合之中;

在数据库中1和y表示真,0和n表示为假;

优先级

常用内置函数

字符串函数





常用日期函数



自定义函数



create or replace function add(int,int,int) returns int
as ’ select $1 + $2 + $3; ’
language sql
returns null on null input;
Create or replace 就是在创建函数的过程中,看是否已经存在了这个函数,如果存在,就更新这个函数,
–删除函数
drop function add(int,int,int)

索引分类

创建与删除索引(默认为B-tree索引)

视图


Insert 批量插入:

将student表里面的数据全部插入进student_new表中

清空一张表


Null值查询,要用is null 或者is not null

将null值放在最后。

显示数据,煤业显示5条,

对结果集做合并操作

Unio all会产生产生重复数据,union就会把重复数据去点


未完待续…

猜你喜欢

转载自blog.csdn.net/m0_56981185/article/details/126519457