postgrepsql sql实例

1.java postgre时间类型映射
postgrejava
date(年月日)java.sql.Date
time(时分秒)java.sql.Time
timetz(时分秒.时区)java.sql.Time
timestamp(年月日 时分秒纳秒(毫微秒))java.sql.Timestamp/java.util.Date
timestamptz(年月日 时分秒.时区)java.sql.Timestamp/java.util.Date
2.字符串截取

split_part(被分隔字段名称,分隔符号,取第几个)
concat_ws(xxx,xx,…)其中之一为null,任然拼接;
concat(xxx,xx,…)其中之一为null,不拼接,返回null;

-- 截取、拼接、重新赋值
update "process_map" set file_url=  concat_ws('https://qes.leiovo.com',SPLIT_PART(file_url,'.leiovo.com',2))  where file_url is not null;
3.sql实例
    <select id="getIssueDoneTask" resultType="com.leiovo.qit.ffrp.web.vo.IssueAssignMeVo">
    -- 1. 创建临时表tmp_isseinfo
        with tmp_issueinfo as (
        select *
        from issueinfo
        where ownerID = #{userId}
        and updatetime &gt;= (
        -- 子查询,获取最近的、有数据的一个月的时间点;
        -- 或者采用传参的方式:
        -- and  updateTime &gt;=  (#{param.lastTime}::Timestamp - interval '1 month')
            select  to_char((max(updatetime)::timestamp + '-1 month'),'yyyy-mm-dd') :: timestamp
            from issueinfo
            where ownerID = #{userId}
        )
        ORDER BY updatetime DESC
        ),
  -- 2. 创建临时表tmp_app_updatetime
        tmp_app_updatetime as (
            select a.issueid as issueid, max(logtime) as logtime
            from issuelog a
            join tmp_issueinfo b on a.issueid = b.issueid
            GROUP BY a.issueid
        )
  -- 3. 使用临时表作关联,缩小查询范围,提升性能
        select a.issueid as issueID, 'issue' as processName, c.itemname as stateName,
        a.createby as creatorName, a.createtime as createTime,
        u.itcode as updatedName, d.logtime as updateTime
        from tmp_issueinfo a
        join dictionaryItem c on a.stateID = c.itemID
        join tmp_app_updatetime d on d.issueid = a.issueid
        join issuelog l on l.issueid = d.issueid and l.logtime = d.logtime
        join userinfo u on l.ownerid = u.userid
        where 1=1
        <if test="param.keyWord != null and param.keyWord != ''">
            and concat_ws('issue',a.issueid,a.createBy,c.itemname,u.realname) ilike concat('%',#{param.keyWord},'%')
        </if>
        ORDER BY updateTime DESC;
    </select>
PostgreSQL 是一个开源的对象关系型数据库管理系统(ORDBMS),以其可靠性、可扩展性和功能强大而闻名。PostGrepSQL(可能是指 Postgres 查询增强工具 PostGIS)是对 PostgreSQL 的扩展,专注于地理空间数据处理。PostGIS 提供了对地理空间数据类型的支持,以及用于处理、分析和可视化地理位置信息的丰富功能。 学习 PostgreSQLPostGIS 可以按照以下步骤进行: 1. **基础知识**:开始时,了解 SQL(结构化查询语言)的基础,包括表、数据类型、查询、索引等。因为 PostGIS 建立在 PostgreSQL 之上,对 SQL 的理解至关重要。 2. **安装与配置**:安装 PostgreSQL,并配置环境变量以便使用命令行工具或图形界面客户端(如 pgAdmin)。 3. **PostGIS 安装**:如果 PostgreSQL 服务器没有集成 PostGIS,你需要安装它。这通常作为附加模块在 PostgreSQL 中进行配置。 4. **地理空间数据类型**:学习如何在 PostgreSQL 中创建和使用几何类型,如 Point, LineString, Polygon 等。 5. **SQL 与 GIS**:熟悉与地理空间相关的 SQL 功能,如 ST_AsText(), ST_Intersects(), ST_GeometryType() 等。 6. **数据操作**:学习如何加载、更新和删除地理空间数据,以及如何执行空间查询和分析。 7. **地图可视化**:学习如何将查询结果转换为地图,可以使用 PostGIS 的内置函数,或者结合 QGIS 或 Leaflet 等前端库。 8. **实践项目**:通过实际项目来应用所学知识,如地图应用开发、数据挖掘或数据分析。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值