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

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
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

Other popular topics Top

New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42576 114
New
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
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement