English 中文(简体)
我如何利用新邮政局数据类型的领域?
原标题:How do I query using fields inside the new PostgreSQL JSON datatype?

我正在寻找在邮政总局9.2号新初专干事职能的一些实例和/或实例。

具体来说,鉴于一系列初专干事的记录:

[
  {name: "Toby", occupation: "Software Engineer"},
  {name: "Zaphod", occupation: "Galactic President"}
]

我将如何写这部书,以找到一份记录?

In vanilla SQL:

SELECT * from json_data WHERE "name" = "Toby"

正式手提手册很稀少:

Update I

I ve put together a gist detailing what is currently possible with PostgreSQL 9.2. Using some custom functions, it is possible to do things like:

SELECT id, json_string(data, name ) FROM things
WHERE json_string(data, name ) LIKE  G% ;

Update II

我现在把我的女神职人员的职能转移到他们自己的项目中:

>PostSQL——将PogreSQL和PL/v8变成一份完全繁多的JSON文件储存的一套功能

最佳回答

Postgres 9.2

页: 1 Andrew Dunstan on the pgsql-hackers list:

At some stage there will possibly be some json-processing (as opposed to json-producing) functions, but not in 9.2.

难道不能阻止他在PLV8中提供应该解决你的问题的榜样。 (链接现已死亡,见现代网站:。)

Postgres 9.3

• 提供新功能和操作人员,增加“json-process”。

回答原始问题,载于第9.3号:

表格:

CREATE TABLE json_tbl (data json);

学历:

SELECT object
FROM   json_tbl
     , json_array_elements(data) AS object
WHERE  object->> name  =  Toby ;

先进实例:

在较大的表格中,您不妨增加一个表述指数,以提高业绩:

Postgres 9.4

添加<><>条码>jsonb (b) 用于“组合”,价值作为本地邮政类型储存,而则属于“。 除上述表述索引外,jsonb 还支持GIN, btree and hashindexes, GIN是其中最强大的力量。

The manual goes as far as suggesting:

In general, most applications should prefer to store JSON data as jsonb, unless there are quite specialized needs, such as legacy assumptions about ordering of object keys.

Bold emphasis mine.
Also, performance benefits from general improvements to GIN indexes.

Postgres 9.5

页: 1 添加更多的功能,以操纵jsonb已到位并显示。

自那时以来,每个主要的邮政版本的功能和业绩都得到了改善。 截至现在,它基本完成(截至第16号邮政)。 ......的一个主要显著增加

Postgres 12

......是SQL/JSON病态语言以及操作人员和职能。 现在,对某一表格(<编码>jsonb)的答复可以:

CREATE TABLE jsonb_tbl (data jsonb);

SELECT jsonb_path_query_first(data,  $[*] ? (@.name == "Toby") ) AS object
FROM   jsonb_tbl
WHERE  data @>  [{"name": "Toby"}] ;  -- optional, for index support

或等同:

...
WHERE  data @@  $[*].name == "Toby" ;

https://dbfiddle.uk/pRK2QHpQ”rel=“nofollow noreferer”>fiddle

See:

大约索引:

问题回答

With Postgres 9.3+, just use the -> operator. For example,

SlectT data->text ->thumbnail ->url AS thumb from instagram;

http://clarkdave.net/06/what-can-you-do-with-postgresql-and-json/“rel=“noreferer” http://clarkdave.net/06/what-can-you-do-with-postgresql-and-json/。 某些冰箱的例子和辅导。

邮政9.3 用途->用途使用。 4 例

种子。

se = SmartElement.new
se.data = 
{
    params:
    [
        {
            type: 1,
            code: 1,
            value: 2012,
            description:  year of producction 
        },
        {
            type: 1,
            code: 2,
            value: 30,
            description:  length 
        }
    ]
}

se.save

铁路c

SELECT data-> params ->0 as data FROM smart_elements;

回返s

                                 data
----------------------------------------------------------------------
 {"type":1,"code":1,"value":2012,"description":"year of producction"}
(1 row)

您可以继续nes

SELECT data-> params ->0-> type  as data FROM smart_elements;

回返

 data
------
 1
(1 row)




相关问题
摘录数据

我如何将Excel板的数据输入我的Django应用? I m将PosgreSQL数据库作为数据库。

Postgres dump of only parts of tables for a dev snapshot

On production our database is a few hundred gigabytes in size. For development and testing, we need to create snapshots of this database that are functionally equivalent, but which are only 10 or 20 ...

How to join attributes in sql select statement?

I want to join few attributes in select statement as one for example select id, (name + + surname + + age) as info from users this doesn t work, how to do it? I m using postgreSQL.

What text encoding to use?

I need to setup my PostgreSQL DB s text encoding to handle non-American English characters that you d find showing up in languages such as German, Spanish, and French. What character encoding should ...

SQL LIKE condition to check for integer?

I am using a set of SQL LIKE conditions to go through the alphabet and list all items beginning with the appropriate letter, e.g. to get all books where the title starts with the letter "A": SELECT * ...

热门标签