Saya tidak tahu bagaimana cara memperbarui elemen dalam tipe data PostgreSQL 9.3.
Contoh saya:
CREATE TABLE "user"
(
id uuid NOT NULL,
password character varying(255),
profiles json,
gender integer NOT NULL DEFAULT 0,
created timestamp with time zone,
connected timestamp with time zone,
modified timestamp with time zone,
active integer NOT NULL DEFAULT 1,
settings json,
seo character varying(255) NOT NULL,
CONSTRAINT id_1 PRIMARY KEY (id)
)
WITH (
OIDS=TRUE
);
ALTER TABLE "user"
OWNER TO postgres;
Bagian json di "profil"
{
"Facebook": {
"identifier": "xxxxxxxxxxx",
"profileURL": "none",
"webSiteURL": "none",
"photoURL": "none",
"displayName": "test2 test2",
"description": "none",
"firstName": "test2",
"lastName": "test2",
"gender": 2,
"language": "none",
"age": "none",
"birthDay": "none",
"birthMonth": "none",
"birthYear": "none",
"email": "[email protected]",
"emailVerified": "none",
"Added": null,
"phone": "none",
"address": "none",
"country": "none",
"region": "none",
"city": "none",
"zip": "none"
},
"Google": {
"identifier": "xxxxxxxxxxxxxxxxxxxxxx",
"profileURL": "none",
"webSiteURL": "none",
"photoURL": "none",
"displayName": "test2 test2",
"description": "none",
"firstName": "test2",
"lastName": "test2",
"gender": 2,
"language": "none",
"age": "none",
"birthDay": "none",
"birthMonth": "none",
"birthYear": "none",
"email": "[email protected]",
"emailVerified": "none",
"Added": null,
"phone": "none",
"address": "none",
"country": "none",
"region": "none",
"city": "none",
"zip": "none"
}
}
Saya menggunakan x-edit untuk frontend, dan saya berharap sesuatu seperti ini akan berhasil, tetapi tidak:
UPDATE public.user
SET "profiles"->'Facebook'->'social'->'facebook' = 'test' WHERE` id='id'
Sepertinya saya tidak dapat menemukan informasi tentang cara memperbarui tipe data json.
sumber
Saya pikir Anda harus Memperbarui bidang lengkap pada Postgres 9.3, setidaknya inilah yang dikatakan oleh dokumentasi kepada saya.
Memperbarui setiap elemen dalam dokumen JSON akan menjadi 9,4 jika saya tidak salah.
sumber
Coba ini
sumber