PostgreSQL基本操作

1.查询某个表的所在磁盘大小

select pg_size_pretty(pg_relation_size('grb_grid'));

2.插入point类型的记录

insert into tb_person ("name", "address", "location", "create_time", "area", "girls")
values ('张三', '武汉', '(101.1,23.0)', '2023-11-22 00:00:00', null, null);

3.插入polygon类型的数据

-- polygon字段,插入时要用两层括号
insert into tb_person ("name", "address", "location", "create_time", "area", "girls")
values ('张三', '武汉', '(101.1,20)', '2023-11-22 00:00:00', '((0,0), (0,1), (1,1), (1,0))', null);

或者用postgis的函数

-- 或者使用postgis插件中的函数,前提时需要安装postgis插件,对于低版本,需要显式指定polygon
INSERT INTO tb_person ("name", "address", "location", "create_time", "area")
VALUES ('张三','武汉','(101.1,20)','2023-11-22 00:00:00',ST_GeomFromText('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0, 0 0))')::polygon);

4.插入int类型的二维数组

INSERT INTO your_table (matrix) VALUES
  (ARRAY[[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
  (ARRAY[[10, 11, 12], [13, 14, 15], [16, 17, 18]]);

5.插入浮点类型的二维数组

定义的时候,用"d_data" float8[][]

INSERT INTO tb_person ("name", "address", "location", "create_time", "area","d_data")
VALUES ('张三','武汉','(101.1,20)','2023-11-22 00:00:00',null, ARRAY[[1.1, 2.2, 3.3], [4.4, 5.5, 6.6], [7.7, 8.8, 9.9]]);

你可能感兴趣的:(postgresql,数据库)