1

I'm using a PostgreSQL 9.4 database. In my bo_lesson table, I have a metadata field that is of jsonb type.

    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                        |

But when I execute this query

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'

The line is properly inserted.

 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

The jsonb field hasn't done any validation on what is inserted. I've read that it it supposed to do so. Did I miss a configuration option?

Patrick
  • 29,357
  • 6
  • 62
  • 90
Hakim
  • 1,084
  • 11
  • 28
  • 1
    The `[` and `}}` in that sample data are misleading - what you're inserting is a double-quoted string, which is a valid JSON value (depending on exact interpretation - see http://stackoverflow.com/questions/18419428/what-is-the-minimum-valid-json). – IMSoP Jul 30 '15 at 13:21
  • Ok, you're right. I'm using PHP, so I think I need to json_encode the data before. I'm receiving a string I guess. Thank you – Hakim Jul 30 '15 at 13:25

0 Answers0