Comments (14)
Please include the full error message. Which oid is failing? We've removed automatic text fallback for types we don't handle by default which is probably causing this error.
from postgrex.
I'm seeing:
** (ArgumentError) no extension found for oid `114`
(postgrex) lib/postgrex/types.ex:285: Postgrex.Types.fetch!/2
(postgrex) lib/postgrex/types.ex:218: Postgrex.Types.format/2
(postgrex) lib/postgrex/protocol.ex:279: anonymous fn/2 in Postgrex.Protocol.encode_params/1
(elixir) lib/enum.ex:977: anonymous fn/3 in Enum.map/2
(elixir) lib/enum.ex:1261: Enum."-reduce/3-lists^foldl/2-0-"/3
(elixir) lib/enum.ex:977: Enum.map/2
(postgrex) lib/postgrex/protocol.ex:275: Postgrex.Protocol.encode_params/1
(postgrex) lib/postgrex/protocol.ex:245: Postgrex.Protocol.send_params/2
after attempting an insert on a table that has a json column in it.
from postgrex.
@jasonwebster oid 114 is json. See the readme for an example json extension.
from postgrex.
I have a table called 'subjects' which has a jsonb
column, bellow is the full error message:
05:21:16.182 [debug] SELECT s0."id", s0."data" FROM "subjects" AS s0 LIMIT 1 [] (61.8ms)
**
(ArgumentError) no extension found for oid `3802`
(postgrex) lib/postgrex/types.ex:285: Postgrex.Types.fetch!/2
(postgrex) lib/postgrex/types.ex:218: Postgrex.Types.format/2
(elixir) lib/enum.ex:977: Enum."-map/2-lc$^0/1-0-"/2
(elixir) lib/enum.ex:977: Enum."-map/2-lc$^0/1-0-"/2
(postgrex) lib/postgrex/protocol.ex:124: Postgrex.Protocol.message/3
(postgrex) lib/postgrex/connection.ex:428: Postgrex.Connection.new_data/2
(postgrex) lib/postgrex/connection.ex:302: Postgrex.Connection.handle_info/2
(stdlib) gen_server.erl:599: :gen_server.handle_msg/5
from postgrex.
You fix it the same way. Just change type: "json"
to type: "jsonb"
.
from postgrex.
THANKS! It's working now!
from postgrex.
@zipme how do you parse the jsonb format? throw me a bone here :) 🍖
from postgrex.
@cmelgarejo I use the example code from README:
defmodule Extensions.JSON do
alias Postgrex.TypeInfo
@behaviour Postgrex.Extension
@json ["json", "jsonb"]
def init(_parameters, opts),
do: Keyword.fetch!(opts, :library)
def matching(_library),
do: [type: "json", type: "jsonb"]
def format(_library),
do: :binary
def encode(%TypeInfo{type: type}, map, _state, library) when type in @json,
do: library.encode!(map)
def decode(%TypeInfo{type: type}, json, _state, library) when type in @json,
do: library.decode!(json)
end
from postgrex.
Yeah, I did too, but when you select a table with jsonb data, the poison library fails to parse the binary data, that's what I meant :(
-----Mensaje original-----
De: "zipme" [email protected]
Enviado el: 13/03/2015 23:31
Para: "ericmj/postgrex" [email protected]
CC: "Christian Melgarejo Bresanovich" [email protected]
Asunto: Re: postgrex no extension found for oid (#60)
@cmelgarejo I use the example code in README:
defmodule Extensions.JSON do
alias Postgrex.TypeInfo
@behaviour Postgrex.Extension
@JSON ["json", "jsonb"]
def init(_parameters, opts),
do: Keyword.fetch!(opts, :library)
def matching(_library),
do: [type: "json", type: "jsonb"]
def format(_library),
do: :binary
def encode(%TypeInfo{type: type}, map, _state, library) when type in @JSON,
do: library.encode!(map)
def decode(%TypeInfo{type: type}, json, _state, library) when type in @JSON,
do: library.decode!(json)
end
—
Reply to this email directly or view it on GitHub.
from postgrex.
Try this:
defmodule JSONB do
alias Postgrex.TypeInfo
@behaviour Postgrex.Extension
def init(_parameters, opts),
do: Keyword.fetch!(opts, :library)
def matching(_library),
do: [type: "jsonb"]
def format(_library),
do: :text
def encode(%TypeInfo{type: "jsonb"}, map, _state, library),
do: library.encode(map)
def decode(%TypeInfo{type: "jsonb"}, json, _state, library),
do: library.decode(to_string(json), keys: :atoms)
end
Where I use Poison to decode/encode json data
from postgrex.
@zipme thanks! worked like a charm! jsonb needed to be decoded as TEXT instead of binary kind of beats the concept 😕
from postgrex.
You should always use the binary format whenever you can because then postgrex can encode/decodes higher types of it (such as arrays and composite types).
binary format jsonb sends a single byte with the version before the json so you can just pattern match that away and then call your json library.
defmodule Extensions.JSON do
alias Postgrex.TypeInfo
@behaviour Postgrex.Extension
@json ["json", "jsonb"]
def init(_parameters, opts),
do: Keyword.fetch!(opts, :library)
def matching(_library),
do: [type: "json", type: "jsonb"]
def format(_library),
do: :binary
def encode(%TypeInfo{type: "json"}, map, _state, library),
do: library.encode!(map)
def encode(%TypeInfo{type: "jsonb"}, map, _state, library),
do: <<1, library.encode!(map)::binary>>
def decode(%TypeInfo{type: "json"}, json, _state, library),
do: library.decode!(json)
def decode(%TypeInfo{type: "jsonb"}, <<1, json::binary>>, _state, library),
do: library.decode!(json)
end
I've also updated the README.
from postgrex.
@ericmj Thanks for the explanation!
@cmelgarejo You should use the above code instead, it works for me.
from postgrex.
Works even better now! :)
Thanks alot @ericmj and @zipme ! 🍻
from postgrex.
Related Issues (20)
- Unhandled gen_statem Timout Event
- There seems to be something wrong with 0.17 when using subscriptions HOT 5
- Dialyzer error in TypeModule HOT 2
- Incorrect documentation for ssl configuration with Failover
- Closing the connection leaves a query running HOT 2
- Unable to connect to Clickhouse (postgresql compatible protocol) HOT 3
- "missed message" exit and shutdown with Elixir release HOT 5
- {:array, :string} does not allow for persisting whitespace strings in the array HOT 2
- ReplicationConnection: durable replication slots re-process events on restart/reconnect HOT 9
- ReplicationConnection: arg to debug errors in callback HOT 9
- Preserve time precision when we decode a time HOT 1
- Hex link points to a different repository and description is incorrect HOT 2
- Database connections keeps on getting disconnected HOT 1
- Set "ssl: [cacertfile: path/to/file]" instead HOT 9
- Relax restriction on allowed year for Date HOT 1
- Support Elixir durations HOT 3
- failed to start child: Postgrex.Notifications HOT 5
- Should the stream be closed before final call in Postgrex.ReplicationConnection HOT 3
- Dialyzer error with Duration HOT 2
- Dialyzer errors after 0.18.0 -> 0.19.0 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from postgrex.