{"action":"created","issue":{"url":"https://api.github.com/repos/go-pg/pg/issues/299","repository_url":"https://api.github.com/repos/go-pg/pg","labels_url":"https://api.github.com/repos/go-pg/pg/issues/299/labels{/name}","comments_url":"https://api.github.com/repos/go-pg/pg/issues/299/comments","events_url":"https://api.github.com/repos/go-pg/pg/issues/299/events","html_url":"https://github.com/go-pg/pg/issues/299","id":172483576,"number":299,"title":"Error: pg: Scan(nil) when scanning JSONB field to interface{}","user":{"login":"joelclouddistrict","id":17000798,"avatar_url":"https://avatars.githubusercontent.com/u/17000798?v=3","gravatar_id":"","url":"https://api.github.com/users/joelclouddistrict","html_url":"https://github.com/joelclouddistrict","followers_url":"https://api.github.com/users/joelclouddistrict/followers","following_url":"https://api.github.com/users/joelclouddistrict/following{/other_user}","gists_url":"https://api.github.com/users/joelclouddistrict/gists{/gist_id}","starred_url":"https://api.github.com/users/joelclouddistrict/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joelclouddistrict/subscriptions","organizations_url":"https://api.github.com/users/joelclouddistrict/orgs","repos_url":"https://api.github.com/users/joelclouddistrict/repos","events_url":"https://api.github.com/users/joelclouddistrict/events{/privacy}","received_events_url":"https://api.github.com/users/joelclouddistrict/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-08-22T15:33:14Z","updated_at":"2016-08-23T11:40:05Z","closed_at":"2016-08-23T09:57:00Z","body":"Hello, I am not able to retrieve data for the following model:\r\n\r\n```\r\ntype ModelEvent struct {\r\n\tTableName struct{} `sql:\"events,alias:events\"`\r\n\tId\t\t     int64\r\n\t**Metadata     interface{}**\r\n\tCreated      time.Time\r\n\tUpdated      time.Time\r\n\tDeleted      time.Time `sql:\",null\"`\r\n}\r\n\r\n```\r\nFrom this table:\r\n\r\n```\r\nCREATE TABLE IF NOT EXISTS events (\r\n    id              SERIAL,\r\n    **metadata        JSONB,**\r\n    created         TIMESTAMP NOT NULL DEFAULT NOW(),\r\n    updated         TIMESTAMP NOT NULL DEFAULT NOW(),\r\n    deleted         TIMESTAMP DEFAULT NULL,\r\n\r\n    CONSTRAINT events_pkey PRIMARY KEY (id)\r\n)\r\n```\r\n\r\nI am able to insert data correctly but when I try to select a list of events with:\r\n\r\n```\r\nvar mEvents []ModelEvent\r\nq := p.Pool.Model(&mEvents).\r\n      Order(\"id ASC\")\r\ncount, err := q.SelectAndCount()\r\n```\r\n\r\nThe function SelectAndCount() returns the error: **pg: Scan(nil)**. I have traced the error and it happens because the **fieldByIndex** function in line 61 of fields.go returns nil, and then **scanIfaceValue** in scan_value.go verifies that that value is nil and returns the error.\r\n\r\nHow should I work with JSONB columns? My intention is to have a field with a variable structure.\r\n\r\nThank you."},"comment":{"url":"https://api.github.com/repos/go-pg/pg/issues/comments/241704860","html_url":"https://github.com/go-pg/pg/issues/299#issuecomment-241704860","issue_url":"https://api.github.com/repos/go-pg/pg/issues/299","id":241704860,"user":{"login":"joelclouddistrict","id":17000798,"avatar_url":"https://avatars.githubusercontent.com/u/17000798?v=3","gravatar_id":"","url":"https://api.github.com/users/joelclouddistrict","html_url":"https://github.com/joelclouddistrict","followers_url":"https://api.github.com/users/joelclouddistrict/followers","following_url":"https://api.github.com/users/joelclouddistrict/following{/other_user}","gists_url":"https://api.github.com/users/joelclouddistrict/gists{/gist_id}","starred_url":"https://api.github.com/users/joelclouddistrict/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joelclouddistrict/subscriptions","organizations_url":"https://api.github.com/users/joelclouddistrict/orgs","repos_url":"https://api.github.com/users/joelclouddistrict/repos","events_url":"https://api.github.com/users/joelclouddistrict/events{/privacy}","received_events_url":"https://api.github.com/users/joelclouddistrict/received_events","type":"User","site_admin":false},"created_at":"2016-08-23T11:40:05Z","updated_at":"2016-08-23T11:40:05Z","body":"Now works correctly, thank you."}}
{"actor":{"display_login":"joelclouddistrict"}}