0

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 format instead of as Elixir data).

Ideally, it takes an arbitrary Elixir value and formats it into a Postgres datum. I strongly suspect something like this exists in Postgrex. I read this (https://hexdocs.pm/postgrex/Postgrex.Extension.html#callbacks) and it mentions encode(state) but it isn't clear if that does what I'm trying to do (it appears most likely not)

If anyone has advice on how I can go about this it's immensely appreciated. Thanks!

Alex V
  • 3,416
  • 2
  • 33
  • 52
  • You have this question tagged with ecto. Are you using ecto? If you are, it will take care of all of this for you. – Justin Wood Jul 10 '19 at 18:41
  • @JustinWood I want to get the data from a remote db in a stream and place it in an identical table in a local db. It's a lot of data so I want it to transfer in a stream (which Postgrex supports). Can I do that with Ecto? – Alex V Jul 10 '19 at 18:46
  • 1
    Yes. create two repositories, and then you can use [`MyApp.Repo.stream/2`](https://hexdocs.pm/ecto/Ecto.Repo.html#c:stream/2) to stream it and put it into another DB. You may also just choose to use tools native to postgres to dump and reload the table. – Justin Wood Jul 10 '19 at 18:54
  • Thanks @JustinWood! `Ecto.Repo.stream` looks like exactly what I need! – Alex V Jul 10 '19 at 19:05

0 Answers0