Je n'arrive pas à comprendre comment mettre à jour un élément dans un type de données PostgreSQL 9.3.
Mon exemple:
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;
La partie json dans les "profils"
{
"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"
}
}
J'utilise x-edit pour le frontend, et j'espérais que quelque chose comme ça fonctionnerait, mais cela ne fonctionne pas:
UPDATE public.user
SET "profiles"->'Facebook'->'social'->'facebook' = 'test' WHERE` id='id'
Je n'arrive pas à trouver d'informations sur la mise à jour d'un type de données json.
la source
Je pense que vous devrez mettre à jour le champ complet sur Postgres 9.3, du moins c'est ce que la documentation me dit.
La mise à jour des éléments individuels dans un document JSON se fera en 9.4 si je ne me trompe pas.
la source
Essaye ça
la source