简体   繁体   中英

Postgres JSON field

I have a table

CREATE TABLE table_a
(
  id bigint NOT NULL,
  name json,
  CONSTRAINT table_a_pkey PRIMARY KEY (id)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE table_a
  OWNER TO postgres;

Data in the table:

1;"{"ru":"Название","en":"Name"}"
2;"{"ru":"Название","en":"Name"}"

When I trying select the name

SELECT id, name->'en'::text as name from table_a;

have next results:

1;""Name""
2;""Name""

How I can select data without quotes?

Thanks!

The -> operator returns JSON . Try using ->> operator - it returns varchar . Something like:

SELECT id, name->>'en'::text as name from table_a;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM