如何在 Postgres 中添加新的 JSON 列
How to add new JSON column in Postgres
我正在尝试向 table 添加一个 json 类型列,但它不起作用,我无法获得正常示例,我做错了什么?
ALTER TABLE user ADD COLUMN purshased_product SET DATA TYPE JSONB USING purshased_product::JSONB;
我不是要更改列,只是创建一个 json 类型
的新列
@Convert(converter = PurshasedProductConverter.class)
private PurshasedProductConverter[] purshasedProducts;
我的变量
要添加新列,请使用:
ALTER TABLE "user" ADD COLUMN purshased_product jsonb;
在线示例:https://rextester.com/SVST52826
set data type
和 using
子句仅用于修改现有列。
请注意 user
是保留关键字。使用该名称创建 table 是个坏主意。如果你坚持这样做,你 必须 每次引用 table 时使用双引号(就像我一样)
示例:
ALTER TABLE schema.t_my_table
ADD COLUMN purshased_product jsonb; (You may also use the type json)
请检查 here 以了解差异。在两种数据类型 json 和 jsonb 之间。
The data types json and jsonb, as defined by the PostgreSQL
documentation,are almost identical; the key difference is that json
data is stored as an exact copy of the JSON input text, whereas jsonb
stores data in a decomposed binary form; that is, not as an
ASCII/UTF-8 string, but as binary code.
我正在尝试向 table 添加一个 json 类型列,但它不起作用,我无法获得正常示例,我做错了什么?
ALTER TABLE user ADD COLUMN purshased_product SET DATA TYPE JSONB USING purshased_product::JSONB;
我不是要更改列,只是创建一个 json 类型
的新列@Convert(converter = PurshasedProductConverter.class)
private PurshasedProductConverter[] purshasedProducts;
我的变量
要添加新列,请使用:
ALTER TABLE "user" ADD COLUMN purshased_product jsonb;
在线示例:https://rextester.com/SVST52826
set data type
和 using
子句仅用于修改现有列。
请注意 user
是保留关键字。使用该名称创建 table 是个坏主意。如果你坚持这样做,你 必须 每次引用 table 时使用双引号(就像我一样)
示例:
ALTER TABLE schema.t_my_table
ADD COLUMN purshased_product jsonb; (You may also use the type json)
请检查 here 以了解差异。在两种数据类型 json 和 jsonb 之间。
The data types json and jsonb, as defined by the PostgreSQL documentation,are almost identical; the key difference is that json data is stored as an exact copy of the JSON input text, whereas jsonb stores data in a decomposed binary form; that is, not as an ASCII/UTF-8 string, but as binary code.