Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PostgreSQL 9.4中的jsonb类型未正确验证_Postgresql_Validation_Jsonb - Fatal编程技术网

PostgreSQL 9.4中的jsonb类型未正确验证

PostgreSQL 9.4中的jsonb类型未正确验证,postgresql,validation,jsonb,Postgresql,Validation,Jsonb,我使用的是PostgreSQL 9.4数据库。在我的bo_课程表中,我有一个metadata字段,它是jsonb类型 Column | Type | Modifiers | ---------------+--------------------------------+---------------------------------| id | intege

我使用的是PostgreSQL 9.4数据库。在我的
bo_课程
表中,我有一个
metadata
字段,它是
jsonb
类型

    Column     |              Type              |            Modifiers            |
---------------+--------------------------------+---------------------------------|
 id            | integer                        | not null                        |
 level         | integer                        |                                 |
 slug          | text                           | not null                        |
 description   | text                           |                                 |
 external_link | character varying(255)         | default NULL::character varying |
 metadata      | jsonb                          |                                 |
 name          | character varying(255)         | not null                        |
 created_at    | timestamp(0) without time zone | not null                        |
 updated_at    | timestamp(0) without time zone | not null                        |
 status        | character varying(45)          | not null                        |
但是当我执行这个查询时

INSERT INTO bo_lesson (id, level, slug, description, external_link, metadata, name,
                       created_at, updated_at, status)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)

parameters: $1 = '4', $2 = '1', $3 = 'education-3', $4 = NULL, $5 = NULL, 
            $6 = '"what ever [ i need }} \""', $7 = 'education', 
            $8 = '2015-07-30 14:33:01', $9 = '2015-07-30 14:33:01', $10 = 'draft'
线路已正确插入

 id | level |    slug     | description | external_link |             metadata       |   name    |     created_at      |     updated_at      | status 
----+-------+-------------+-------------+---------------+----------------------------+-----------+---------------------+---------------------+--------
  4 |     1 | education-3 |             |               | "what ever [ i need }} \"" | education | 2015-07-30 14:33:01 | 2015-07-30 14:33:01 | draft

jsonb
字段没有对插入的内容进行任何验证。我读到它应该这样做。我是否错过了配置选项?

该示例数据中的
[
}
有误导性-插入的是双引号字符串,这是一个有效的JSON值(取决于确切的解释-请参阅).好的,你说得对。我使用的是PHP,所以我想我需要在之前对数据进行json编码。我想我收到的是一个字符串。谢谢你示例数据中的
[
}
是误导性的-你插入的是一个双引号字符串,这是一个有效的json值(取决于确切的解释-请参阅).好的,你说得对。我使用的是PHP,所以我想我需要先对数据进行json_编码。我想我收到了一个字符串。谢谢