问题标签 [postgresql-9.3]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
17 回答
18269 浏览

database - PostgreSQL 的隐藏特性

我很惊讶这还没有发布。您在 Postgres 中知道哪些有趣的技巧?晦涩的配置选项和缩放/性能技巧特别受欢迎。

我相信我们可以击败相应MySQL 线程上的 9 条评论:)

0 投票
3 回答
217467 浏览

sql - 如何使用新的 PostgreSQL JSON 数据类型中的字段进行查询?

我正在为 PostgreSQL 9.2 中的新 JSON 函数寻找一些文档和/或示例。

具体来说,给定一系列 JSON 记录:

我将如何编写 SQL 以按名称查找记录?

在普通 SQL 中:

官方开发手册非常稀少:

更新一

我整理了一个要点,详细说明了 PostgreSQL 9.2 目前可能实现的功能。使用一些自定义函数,可以执行以下操作:

更新二

我现在已经将我的 JSON 函数移到了他们自己的项目中:

PostSQL - 一组用于将 PostgreSQL 和 PL/v8 转换为非常棒的 JSON 文档存储的函数

0 投票
1 回答
415 浏览

sql - select from ... - 基于 JSON 格式的值

假设我有一个数据库表,其中包含几个常见的列,例如姓名、性别、年龄……

此外,我还有一个使用 JSON 数据类型(可从 Postgres 9.2 获得)的附加列,在 JSON 中具有任意长度和任意字段:

使用 Postgres 9.3 的新功能,例如,我想返回所有带有职业 = 足球的行。

像这样的伪:select * from table where json_field.occupation = football

有没有办法做到这一点?

0 投票
1 回答
75582 浏览

json - How to create index on JSON field in Postgres?

In PostgreSQL 9.3 Beta 2 (?), how do I create an index on a JSON field? I tried it using the -> operator used for hstore but got the following error:

ERROR: data type json has no default operator class for access method "btree" HINT: You must specify an operator class for the index or define a default operator class for the data type.

0 投票
3 回答
2214 浏览

php - postgresql 相当于 $mysqli->insert_id

在 postgresql 9.3 中是否有相当于 $mysqli->insert_id 的东西?我正在导入一个表,但我需要获取表中创建的最后一个主键并将其应用为第二个表中的外键?表1---->表2完成一条记录。

更多信息:

**使用上面的 sql,我插入我的记录,然后我将如何在我的下一个 SQL 插入中使用它,如果我使用返回 id,这个 ID 存储在哪里,我如何在另一个 INSERT 语句中使用它?

0 投票
1 回答
8234 浏览

postgresql - SELECT CURRVAL (pg_get_serial_sequence 我做错了什么?

我做错了什么,我试图从表中获取最后一个record_id,在第一条语句将它插入我的表之后。我似乎只是打印用于显示最后一个 id 的代码?

代码在这里

0 投票
1 回答
8002 浏览

postgresql-9.3 - 如何在 postgresql 9.3 中的 JSON 类型列上使用 JSON 运算符

谁能明白为什么这不起作用?根据手册第 9.15 节->,操作员应访问 JSON 数据类型的元素。在我看来,虽然信息架构说该列是“json”类型,但它仍然是一个标量字符串(请注意显示时的引号。)

更新:

我在这里这里发现了这两个帖子,表明它应该完全按照我的方式工作。只是为了确定我试过这个:

是否有我需要获取 JSON 功能的构建选项或贡献模块?

0 投票
21 回答
370397 浏览

json - 如何修改新 PostgreSQL JSON 数据类型中的字段?

使用 postgresql 9.3,我可以SELECT使用 JSON 数据类型的特定字段,但是如何使用 修改它们UPDATE?我在 postgresql 文档或在线任何地方都找不到这方面的任何示例。我已经尝试了明显的:

0 投票
2 回答
16930 浏览

json - Are postgres JSON indexes efficient enough compared with classic normalized tables?

Current Postgresql versions have introduced various features for JSON content, but I'm concerned if I really should use them - I mean, there is not yet "best practice" estabilished on what works and what doesn't, or at least I can't find it.

I have a specific example - I have a table about objects which, among other things, contains a list of alternate names for that object. All that data will also be included in a JSON column for retrieval purposes. For example (skipping all the other irrelevant fields).

I will need some queries in the form "list all objects where one of altnames is 'foobar'." The expected table size is on the order of a few million records. Postgres JSON queries can be used for that, and it can also be indexed (Index for finding an element in a JSON array, for example). However, SHOULD it be done that way or is it a perverse workaround that's not recommended?

The classic alternative, of course, is to add an additional table for that one-to-many relation, containing the name and a foreign key to the main table; the performance of that is well understood. However, that has it's own disadvantages as then it means either data duplication between that table and JSON (with possible integrity risk); or creating that JSON return data dynamically at every request, which has it's own performance penalty.

0 投票
1 回答
4536 浏览

postgresql - Postgresql 在重新创建表后忘记了授权

我们使用 liquibase 来管理和执行我们的数据库更改。在我们的 DEV 环境中(尤其是在本地机器上),我们经常重新创建表以保持清白。我们刚刚从 MySQL 迁移到 Postgres,并面临与这些表重新创建相关的问题。

最初,我们已授予我们的 DB 用户:

这是在连接到我们自己的数据库后通过psql执行的(其中 public 是默认/唯一模式)。

一切都很好,直到我们要求 liquibase 重新创建表,在这种情况下它将删除所有表并重新创建它们。

之后,mydbuser似乎失去了对表的所有授权。

根据几个资源(像这样)我们需要改变默认权限,所以我们服从:

然而,尽管这看起来很合乎逻辑,但它并没有改变什么。重新创建表后,所有授权(甚至选择)仍然丢失。

我们做错了什么或者我们还需要做什么?

更新

\ddp 显示:默认访问权限

所有者 | 架构 | 类型 | 访问权限
----------+--------+----------+------ ---
postgres | 公共 | 序列 | mydb=rU/postgres
postgres | 公共 | 表| mydb=arwd/postgres