给定这样的jsonb类型列和数据结构:
{ "1": 10000.2, "2": 77.2, "3": -200.09, "4": 12.55 }
需要从这个json检索结果并通过VALUE进行排序
SELECT * FROM jsonb_each(
(SELECT jsonb_column FROM table WHERE id = 777)
)
ORDER BY VALUE DESC
LIMIT 100
是的,这给出了正确的结果,但问题是,按jsonb类型排序有多可靠?(因为VALUE是jsonb类型
我使用的是postgres 12.5。我一直在研究如何获得组成唯一索引的列的名称的答案。在结合了StackOverflow和其他地方的一些答案后,我提出了这个解决方案
select i.relname as index_name,
a.attname as column_name
from pg_class c
inner join pg_index ix on c.oid=ix.indrelid
inner join pg_class i on ix.indexrelid=i.oid
inner join pg_attribute a on a.attreli
我的表中有一个jsonb列-它包含json对象的数组,这些对象中的一个字段是date。现在,我在表中添加了timestamp类型的新列。现在我需要一条语句,帮助我用jsonb数组列中的最新日期值更新新列。
下面的语句可以很好地从特定记录的jsonb数组列中选择最近的日期:
select history.date
from document,
jsonb_to_recordset(document.history) as history(date date)
where document.id = 'd093d6b0-702f-11eb-9439-0242ac13000
我正在尝试用另一列的值更新json日期字段。
我可以通过以下声明更新情况:
UPDATE table
SET column = column || '{"date_field":"2022-08-25"}'
where id = 123;
当我尝试用另一列的值更新时,例如:
UPDATE table
SET json_column = json_column || '{"date_field":column}'
where id = 123;
我会得到以下错误。
错误: json类型的输入语法无效
在postgresql数据库表中有一个名为authors的jsonb列,其数据如下所示:
[{"id":134,"nameKey":"smith, john"},
{"id":112,"nameKey":"bats, billy"}]
如何从jsonb author列包含id 112的作者的表中返回所有行?
我需要一些类似的东西
select * from record
where authors -> id = 2
我也需要知道名字:
select * from gardner_recor
表user_record有列info,它返回以下数据,而info是jsonb列。
查询: Select info from user_record;
结果:
{"someId": "XXFUN0123XX", "age": 43, "updatedAt": "2017-02-18 00:00:00"}
现在问题是专门针对来自json响应的updatedAt字段的。
select info ->> 'updatedAt' from user_record where id='XXF
我正在使用Postgres 9.4。我有一个JSONB字段:
Column │ Type │ Modifiers
─────────────────┼──────────────────────┼────────────────────────────────────────────────────────────────────
id │ integer │ not null default
practice_id │ c