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

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
vac
Hi, I’m quite new in Elixir and I’m trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and I...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
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
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
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

Other popular topics Top

albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

We're in Beta

About us Mission Statement