postgresql
文章平均质量分 56
Fitz_GuangChen
这个作者很懒,什么都没留下…
展开
-
Ubuntu20.04 - Postgresql(pg10)离线主从搭建
环境信息> 主节点:192.168.99.106 从节点:192.168.99.1051. 下载ubuntu下的postgresql离线包(pg10)注: 此处可从国内开源站点获取,例:清华源 https://mirrors.tuna.tsinghua.edu.cn/ubuntu2. 上传服务器并安装sudo dpkg -i ./*.deb注: 1&2需要两台服务器均安装3. 主服务器配置#先创建一个新目录用来存放归档文件mkdir ...原创 2021-08-03 10:32:56 · 1174 阅读 · 0 评论 -
Python连接postgresql并以字典返回查询结果
Python连接postgresql并以字典返回查询结果一、列表嵌套元组返回import psycopg2# 基本查询,以列表嵌套元组返回[(1, 2, 3), (2, 3, 4), ...]def execute(sql): conn = psycopg2.connect(database=db, user=user, password=password, host=host, port=port) cur = conn.cursor() try: cur原创 2020-12-09 10:47:44 · 2496 阅读 · 1 评论 -
POSTGRESQL 自定义排序规则
业务场景平时我们会遇到某种业务,例如:超市里统计哪一种水果最好卖,并且优先按地区排序,以便下次进货可以多进些货。这种业务就需要我们使用自定义排序规则(当然可以借助多字段多表实现类似需求,但这里将使用最简单的方法--无需多表和多字段,自定义排序规则即可实现)创建表id为数据唯一标识,area为区域,area_code为区域代码,code为水果代码,sale_num为销量,price价格create table sale_fruit_count ( id INTEGER primary原创 2020-07-28 14:16:10 · 6115 阅读 · 2 评论 -
POSTGRESQL 递归树查询
postgresql递归关键字 with recursive r_name as (select ***)使用递归查询可以实现数据的树形查询,代码以下with recursive r as ( select id, parent_id, ARRAY[id] AS path, '' sub_level, 1 dept_level from hr_department where parent_id is null union a原创 2020-07-24 16:54:49 · 439 阅读 · 0 评论