Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 694933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:54:27+00:00 2026-05-14T02:54:27+00:00

After much fiddling, I’ve managed to install the right ODBC driver and have successfully

  • 0

After much fiddling, I’ve managed to install the right ODBC driver and have successfully created a linked server on SQL Server 2008, by which I can access my PostgreSQL db from SQL server.

I’m copying all of the data from some of the tables in the PgSQL DB into SQL Server using merge statements that take the following form:

with mbRemote as 
    (
        select 
            * 
        from 
            openquery(someLinkedDb,'select * from someTable')
    ) 
merge into someTable mbLocal 
using mbRemote on mbLocal.id=mbRemote.id
when matched 
        /*edit*/ 
        /*clause below really speeds things up when many rows are unchanged*/
        /*can you think of anything else?*/
        and not (mbLocal.field1=mbRemote.field1
                and mbLocal.field2=mbRemote.field2
                and mbLocal.field3=mbRemote.field3
                and mbLocal.field4=mbRemote.field4)
        /*end edit*/
        then 
        update
        set
                mbLocal.field1=mbRemote.field1,
                mbLocal.field2=mbRemote.field2,
                mbLocal.field3=mbRemote.field3,
                mbLocal.field4=mbRemote.field4
when not matched then 
        insert
        (
            id,
            field1,
            field2,
            field3,
            field4
        )
        values
        (
            mbRemote.id,
            mbRemote.field1,
            mbRemote.field2,
            mbRemote.field3,
            mbRemote.field4
        )
WHEN NOT MATCHED BY SOURCE then delete;

After this statement completes, the local (SQL Server) copy is fully in sync with the remote (PgSQL server).

A few questions about this approach:

  1. is it sane?
  2. it strikes me that an update will be run over all fields in local rows that haven’t necessarily changed. The only prerequisite is that the local and remote id field match. Is there a more fine grained approach/a way of constraining the merge statment to only update rows that have actually changed?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:54:27+00:00Added an answer on May 14, 2026 at 2:54 am

    That looks like a reasonable method if you’re not able or wanting to use a tool like SSIS.

    You could add in a check on the when matched line to check if changes have occurred, something like:

    when matched and mbLocal.field1 <> mbRemote.field1 then
    

    This many be unwieldy if you have more than a couple of columns to check, so you could add a check column in (like LastUpdatedDate for example) to make this easier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After much confusion, I have finally managed to successfully deploy a instance of Cruise
Right, after much struggle I finally managed to get a sort of shared folder
after much time and effort I have managed to create a map with a
After much searching and googling I am coming back to the well. I have
I have a dilemma on my hands. After much trial and error, I still
Well after much messing about I have finally got a query that gives sales
I just mangaged to install the perl/Tk module after much struggle. I realise I
Recently I have been playing around with the HTTP Proxy in twisted. After much
Possible Duplicate: Python nested functions variable scoping After much trial and error I have
After much research I am still stumped. I have a serial port object which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.