Questions tagged [postgrex]

For questions related to PostgreSQL driver for Elixir.

postgrex is a driver for .

Features:

  • Automatic decoding and encoding of Elixir values to and from PostgreSQL's binary format
  • User defined extensions for encoding and decoding any PostgresSQL type
  • Supports transactions, prepared queries and multiple pools via DBConnection
  • Supports PostgreSQL 8.4, 9.0, 9.1, 9.2, 9.3, 9.4, and 9.5 (hstore is not supported on 8.4)

Additional links:

32 questions
1
vote
0 answers

Querying a bytea field using postgrex

I'm attempting to query a table in postgres with the following: result = Postgrex.query!(pg, "SELECT owner_id, connected_at FROM devices WHERE id = $1", [device_id]) # result = [] The device_id variable is an Elixir string, and this query used…
Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
1
vote
0 answers

How can I fill a local Postgres table with the results of a SELECT statement executed on Amazon Redshift using Postgrex?

The Postgrex documentation gives this excellent example of how to transfer data: Postgrex.transaction(pid, fn(conn) -> query = Postgrex.prepare!(conn, "", "COPY posts TO STDOUT") stream = Postgrex.stream(conn, query, []) result_to_iodata =…
Alex V
  • 3,416
  • 2
  • 33
  • 52
1
vote
1 answer

Postgrex - query returning an ambiguous column reference error

I have the following queries: def user_contacts(provider_id, filter) do query = from( u in User, preload: [:groups], where: u.provider_id == ^provider_id and u.type != "company" ) query |> filter_sector(filter) |>…
Bargain23
  • 1,863
  • 3
  • 29
  • 50
1
vote
1 answer

Why does dumping DateTime to :utc_datetime_usec with a precision less than 6 fail?

I am wondering why I can't dump a DateTime with a precision less than 6? Why can't we just fill up with zeros? Example iex> {:ok, datetime, _} = DateTime.from_iso8601("1970-01-01T00:00:00Z") {:ok, #DateTime<1970-01-01 00:00:00Z>, 0} Expected iex>…
Jan
  • 11
  • 1
1
vote
1 answer

(Postgrex.Error) ERROR 58P01 (undefined_file) $libdir/postgis-2.4

I had to brew reinstall some things that my existing project uses. Now I'm getting this error when I'm running a SELECT statement: Interactive Elixir (1.7.4) - press Ctrl+C to exit (type h() ENTER for help) iex(1)> 18:07:23.636 [debug] QUERY ERROR…
BeniaminoBaggins
  • 11,202
  • 41
  • 152
  • 287
1
vote
2 answers

Allow Ecto queries to run immediately in a test environment?

I'd like to write tests to validate that the SQL queries in my application return data adhering to certain constraints: namely, that return values are presented in descending insertion order. In the application, I'm using timestamps() in my schemas…
pablo.meier
  • 2,339
  • 4
  • 21
  • 29
1
vote
0 answers

(Postgrex.Error) ERROR 22021 (character_not_in_repertoire): invalid byte sequence for encoding "UTF8": 0x92

I'm saving HTML from various websites on the internet and saving it to a simple Postgres text field. This is the error I'm getting: ** (Postgrex.Error) ERROR 22021 (character_not_in_repertoire): invalid byte sequence for encoding "UTF8": 0x92 What…
Sergio Tapia
  • 9,173
  • 12
  • 35
  • 59
1
vote
1 answer

"shutdown: failed to start child: DBConnection.Ownership.Manager" after updating library from Ecto 1 to Ecto 2

I have a library that uses Ecto and Postgrex (Postgrex is only used in tests). After upgrading from Ecto 1 to Ecto 2, the test suite started giving this error: $ mix test Compiling 4 files (.ex) Generated ectoo app ** (EXIT from #PID<0.46.0>)…
Henrik N
  • 15,786
  • 5
  • 82
  • 131
0
votes
1 answer

How to stop a Postgrex process and its TypeServer process?

I have a few thousand databases. I want to connect to each of them in series one by one and issue a query. I do this by starting a Postgrex process like this for each one. {:ok, pid} = Postgrex.start_link( port: database.port, …
Jesse Shieh
  • 4,660
  • 5
  • 34
  • 49
0
votes
1 answer

elixir, ecto: Cannot pass parameter to "CREATE VIEW" raw SQL query

We're building an elixir application, and using ecto to connect to our database. One of the roles of the application is to create reports based on our event store. We decided to write the code for those reports in raw SQL. I need to create a…
aspyct
  • 3,625
  • 7
  • 36
  • 61
0
votes
0 answers

How can I convert an Elixir value to SQL format using Postgrex?

For example, let's say I have a Postgrex date value ~D[2017-11-28]. I'd like to pass that to a hypothetical Postgrex function Postgrex.hypothetical_format_to_sql that will return something like "2017-11-28" (ie, the same data but in PostgreSQL…
Alex V
  • 3,416
  • 2
  • 33
  • 52
0
votes
2 answers

How to override or disable Postgrex timeout setting: 15 seconds?

Working on an Elixir app. There's a Scraper function that copies data from a Google Spreadsheet into a postgres database via the Postgrex driver. The connection through the Google API works fine, but the function always times out after 15 seconds.…
ted.strauss
  • 4,119
  • 4
  • 34
  • 57
0
votes
1 answer

Why does Postgrex - Ecto throw this not_null_violation error?

Error Here's the error that I encountered when I'm testing my Account changeset. It seems like it would only be caused by the Ecto migration with wrongly structured database, but the ecto.migrate runs fine, as also Postgresql doesn't throw any error…
0
votes
1 answer

Postgrex how to define json library

I'm just trying to use Postgrex without any kind of ecto setup, so just the example from the documentation readme. Here is what my module looks like: defmodule Receive do def start(_type, _args) do {:ok, pid} = Postgrex.start_link( …
pizza247
  • 3,869
  • 7
  • 33
  • 47
0
votes
3 answers

Conversion error with a custom DateRange Ecto type

I'm having trouble with a custom Ecto type that I'm writing. It is be backed by %Postgrex.Range{} type. The code is defmodule Foo.Ecto.DateRange do @behaviour Ecto.Type def type, do: :daterange def cast(%{"lower" => lower, "upper" =>…