AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-63909

thames's questions

Martin Hope
thames
Asked: 2019-10-13 16:04:24 +0800 CST

如何过滤触发器中值不为空的 hstore?

  • 1

解释问题的最简单方法是使用审计触发器。

但是,在插入时它会保存所有值,包括空值。我想过滤掉hstore(NEW.*). 最简单/最快的方法是什么?

来源:https ://github.com/2ndQuadrant/audit-trigger/blob/master/audit.sql#L134

audit_row.row_data = hstore(NEW.*) - excluded_cols;

这显然不起作用,但希望能解释答案的样子。

audit_row.row_data = hstore(hstore(NEW.*) FILTER (WHERE value IS NOT NULL)) - excluded_cols;

首选将回答不使用用户创建的函数,例如仅使用 Postgres 函数/运算符。

这适用于 >= PostgreSQL 11。

我正在寻找一个解决方案hstore,而不是json或jsonb。json具有或jsonb可以包括的替代方式,但是hstore是优选的。

postgresql null
  • 2 个回答
  • 764 Views
Martin Hope
thames
Asked: 2019-03-06 16:30:32 +0800 CST

Postgres:错误:运算符不存在:点 <@> 点

  • 2

在 Windows 上使用 PostgreSQL 11。

两者都由 安装cube和earthdistance验证pg_available_extensions。

重新启动 PostgreSQL。

[42883] ERROR: operator does not exist: point <@> point.

设置:

CREATE EXTENSION IF NOT EXISTS cube SCHEMA temp;
CREATE EXTENSION IF NOT EXISTS earthdistance SCHEMA temp;

尝试了StackOverflow 中的以下代码

create table temp.lat_lon (
  city varchar(50) primary key,
  lat float8 not null,
  lon float8 not null
);

insert into temp.lat_lon values
('London, GB', 51.67234320, 0.14787970),
('New York, NY', 40.91524130, -73.7002720);

select
  (
  (select point(lon,lat) from temp.lat_lon where city = 'London, GB') <@>
  (select point(lon,lat) from temp.lat_lon where city = 'New York, NY')
  ) as distance_miles;

抛出:

[42883] ERROR: operator does not exist: point <@> point.

已安装扩展并重新启动 Postgres。

select * from pg_available_extensions where name IN ('cube', 'earthdistance');

cube            1.4     data type for multidimensional cubes
earthdistance   1.1     calculate great-circle distances on the surface of the Earth

这是因为 Windows 上的 PostgreSQL v11 吗?是的,纬度/经度以正确的顺序排列(长在第一位)。

注:表 F.6 基于点的地球距离算子

关于以下方面的更新:架构/搜索路径:

SELECT extname, extnamespace::regnamespace FROM pg_extension
WHERE  extname IN ('cube', 'earthdistance');

cube            temp
earthdistance   temp
SHOW search_path;

temp

注:I CREATE EXTENSION hstore SCHMEA temp;and can usehstore及其运算符。所以似乎并不是所有的扩展。

postgresql postgresql-extensions
  • 1 个回答
  • 2897 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve