Hasimbola

Hasimbola

Auto-fill Postgres Database via SQL Server datas

I rephrase my question from yesterday because it was not very clear, I want to automatically add the data stored in SQL Server in Postgres, i.e. the data in Postgres is always the same as that in SQL Server, That is to say that if there is an update of data in SQL Server, those in Postgres are also updated.

Postgres is UI-bound and SQL Server is read-only for data retrieval.

My table structure for Postgres and SQL Server is like this :
id , description , price , title , views , inserted_at and updated_at.

I receive format of data like this from SQL Server and how I can to store this into Postgres:

QUERY OK source=“products” db=3.0ms queue=4.8ms idle=1400.1ms
SELECT p0.[id], p0.[description], p0.[price], p0.[title], p0.[views], p0.[inserted_at], p0.[updated_at] FROM [products] AS p0 []
[
%SyncDb.Catalog.Product{
meta: #Ecto.Schema.Metadata<:loaded, “products”>,
description: “taille haute”,
id: 2,
inserted_at: ~N[2022-03-22 00:00:00],
price: #Decimal<2.000000>,
title: “pantalon”,
updated_at: ~N[2022-03-23 00:00:00],
views: 1
},
%SyncDb.Catalog.Product{
meta: #Ecto.Schema.Metadata<:loaded, “products”>,
description: “taille haute”,
id: 3,
inserted_at: ~N[2022-03-22 00:00:00],
price: #Decimal<2.000000>,
title: “pantalon”,
updated_at: ~N[2022-03-23 00:00:00],
views: 1
},
%SyncDb.Catalog.Product{
meta: #Ecto.Schema.Metadata<:loaded, “products”>,
description: “taille haute”,
id: 4,
inserted_at: ~N[2022-03-22 00:00:00],
price: #Decimal<2.000000>,
title: “pantalon”,
updated_at: ~N[2022-03-23 00:00:00],
views: 1
},
%SyncDb.Catalog.Product{
meta: #Ecto.Schema.Metadata<:loaded, “products”>,
description: “taille haute”,
id: 5,
inserted_at: ~N[2022-03-22 00:00:00],
price: #Decimal<2.000000>,
title: “pantalon”,
updated_at: ~N[2022-03-23 00:00:00],
views: 1
},
%SyncDb.Catalog.Product{
meta: #Ecto.Schema.Metadata<:loaded, “products”>,
description: “taille haute”,
id: 6,
inserted_at: ~N[2022-03-22 00:00:00],
price: #Decimal<2.000000>,
title: “pantalon”,
updated_at: ~N[2022-03-23 00:00:00],
views: 1
},
%SyncDb.Catalog.Product{
meta: #Ecto.Schema.Metadata<:loaded, “products”>,
description: “taille haute”,
id: 7,
inserted_at: ~N[2022-03-22 00:00:00],
price: #Decimal<2.000000>,
title: “pantalon”,
updated_at: ~N[2022-03-23 00:00:00],
views: 1
},
%SyncDb.Catalog.Product{
meta: #Ecto.Schema.Metadata<:loaded, “products”>,
description: “taille haute”,
id: 8,
inserted_at: ~N[2022-03-22 00:00:00],
price: #Decimal<2.000000>,
title: “pantalon”,
updated_at: ~N[2022-03-23 00:00:00],
views: 1
},
%SyncDb.Catalog.Product{
meta: #Ecto.Schema.Metadata<:loaded, “products”>,
description: “taille haute”,
id: 9,
inserted_at: ~N[2022-03-22 00:00:00],
price: #Decimal<2.000000>,
title: “pantalon”,
updated_at: ~N[2022-03-23 00:00:00],
views: 1
},
%SyncDb.Catalog.Product{
meta: #Ecto.Schema.Metadata<:loaded, “products”>,
description: “taille haute”,
id: 10,
inserted_at: ~N[2022-03-22 00:00:00],
price: #Decimal<2.000000>,
title: “pantalon”,
updated_at: ~N[2022-03-23 00:00:00],
views: 1
},
%SyncDb.Catalog.Product{
meta: #Ecto.Schema.Metadata<:loaded, “products”>,
description: “taille haute”,
id: 11,
inserted_at: ~N[2022-03-22 00:00:00],
price: #Decimal<2.000000>,
title: “pantalon”,
updated_at: ~N[2022-03-23 00:00:00],
views: 1
},
%SyncDb.Catalog.Product{
meta: #Ecto.Schema.Metadata<:loaded, “products”>,
description: “Taille Xl”,
id: 13,
inserted_at: ~N[2022-03-23 00:00:00],
price: #Decimal<2.000000>,
title: “t-shirt”,
updated_at: ~N[2022-03-24 00:00:00],
views: 1
},
%SyncDb.Catalog.Product{
meta: #Ecto.Schema.Metadata<:loaded, “products”>,
description: “Taille X”,
id: 14,
inserted_at: ~N[2022-03-23 00:00:00],
price: #Decimal<3.000000>,
title: “short”,
updated_at: ~N[2022-03-24 00:00:00],
views: 1
}
]

Can someone help me because I don’t see how it works

Thanks! :smiley: :slight_smile: :pray:

Marked As Solved

Hasimbola

Hasimbola

Hey, I’m really sorry for the late reply:

The solution that I’ve found is like this :

queries = MRepo.all(from a in Product ,
select: a.id)
query = Repo.all(from i in Product,
where: i.id not in ^queries,
select: %{title: i.title,
id: i.id,
description: i.description,
price: i.price,
views: i.views,
inserted_at: i.inserted_at,
updated_at: i.updated_at
}
)

MRepo.insert_all(Product, query)
MRepo.all(Product)

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; someth...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement