Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a query that returns data from sql-server and I need to be able to put the results into PostgreSQL. I'm using C# for the task.

share|improve this question
What have you tried? Have you successfully established connections to both databases from C#? What part are you struggling with? – Aaron Bertrand Jul 24 '13 at 19:28
I have my query constructed but no code yet. I was hoping there would be a smooth way to go about it but I can't think of one and I have a very tight time schedule. I'm probably going to have to loop through each result and insert into PostgreSQL that way. I wasn't sure if there was a smoother way I could go about doing it. Some kind of SELECT INTO for cross DB stuff. – Vap0r Jul 24 '13 at 19:40
There is nothing like the latter, at least not in your inventory - so you have to loop over the data. – dezso Jul 24 '13 at 19:58
@dezso, I'm sorry, I don't understand what you mean by at least not in your inventory Could you expand on that? – Vap0r Jul 24 '13 at 20:02
@Vap0r I am sorry, I meant that (from the PostgreSQL side, which I know much better) I don't see how you can solve this problem with the components you listed in your question. There are software which are designed for similar tasks. But probably lfd is right in his answer and you can just set up a foreign server on the SQL Server side. – dezso Jul 24 '13 at 20:28

I suggest you use an MS SQL Server foreign data wrapper on PostgreSQL, so you need no C# and have the full power of PostgreSQL’s SELECT… INTO.

Failing that, there is also DBI Links which gives you a subset of functionality and lower performance but still should be enough.

Now, if you just need to use C#… perhaps there is a PL/C# that you can leverage.

But, sincerely, this seems to me more to be about which syntax is allowed on C#. Perhaps you should ask in a Npgsql forum

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.