【问题标题】:Accessing postgres data structure访问 postgres 数据结构
【发布时间】:2016-12-24 05:38:20
【问题描述】:

我的 postgres 表中有一个表,其中的数据结构很奇怪。下面是数据结构的一个例子:

id         |        1
name       |        name
data       |        :type: information
           |        :url: url
           |        :platform: 
           |          android: ''
           |          iphone: ''
created_at |        2016-07-29 11:39:44.938359
updated_at |        2016-08-22 12:24:32.734321

例如,我如何更改数据 > 平台 > android?

【问题讨论】:

  • 你的符号比较神秘,data是什么类型的?
  • 对不起。数据类型为text。它是一个奇怪的数据结构。我不认为我是否必须更新单个值,例如android 我将不得不再次输出整个数据内容,包括新值,即update table set data = ':type: information :url: url :platform: android: 'new_value' iphone: '' 我知道这不是正确的方法,但你明白我的意思。谢谢。
  • 不幸的是,Postgres 没有内置方法来更新部分文本,因此您必须手动(或在您的应用程序中)格式化全新的值。
  • 感谢您的信息。似乎是糟糕的数据库设计。明天将与我的同事聊天,并添加我可能获得的任何进一步信息。谢谢。
  • 刚刚意识到我可以运行替换。可能很明显,因为 android 的数据是空的,但可以运行 update table set field = replace(field, 'android: ''''', 'android: ''new_value''')。你觉得这样好吗?

标签: postgresql


【解决方案1】:

只是做了一些更多的研究,发现这个可以解决问题:

postgresql - replace all instances of a string within text field

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-22
    • 1970-01-01
    • 1970-01-01
    • 2010-11-14
    相关资源
    最近更新 更多