Tool to convert t-sql (SQL Server) stored procedure to pgsql (postgre sql)

15,802

Solution 1

Have you seen this page:

Convert from other databases to PostgreSQL?

Solution 2

Translating languages is hard. You need to parse the original (with all the strange syntax and warts it allows above and beyond what the documentation says), determine what names mean, discover the semantics, and translate to the target language without losing the subtle details.

I'd be surprised if you found a solution for this off-the-shelf. Part of the problem is there are a vast number N of source languages (made worse by dialects), and a vast number of targets M, requiring a library of NxM translators to be lying around. And if you wait a few months, N and M both move. One hope is to translate N langauges to a common universal core language, and translate that to M targets, now only requiring N+M... but nobody has found a really universal language, and if you wait a few months, N and M move anyway.

One can consider building (or getting someone else to build) a specific translator for the task; this usually is uneconomical, at least if you want it to be reliable, because so much of the translator machinery (parsing, name resolution, pattern matching/translating, ...) tends to get rebuilt from scratch.

One can amortize the cost of the translator infrastructure if you are careful, by building (a lot of) shared machinery. Once you do that, building a translator is easier (still not easy) and the economics make more sense for individual cases. You can read more about this approach at: What kinds of patterns could I enforce on the code to make it easier to translate to another programming language?

Share:
15,802
Prashant Lakhlani
Author by

Prashant Lakhlani

I am founder of Facile Technolab, a custom software develoment company in India. I have 13+ years experience with Microsoft, Node, Azure/AWS and DevOps related technology stacks. I love challenges and finding way through it. I am passionate about solution big business problems using technology. DevOps and AWS I have 3 years experience handling DevOps and AWS. I can implement CI/CD for your project using jenkins/Azure DevOps, AWS EC2, AWS ECR & ECS, Docker and related DevOps and AWS Stack. Technical Project Manager I have 5+ years experience managing projects, leading technical teams, product development using agile methodology with excellent skills on agile project management, team building, team motivation, goal setting, delivering softwares. .Net and .Net Core Expert I have 10+ years experience working with microsoft technology stack. Depending on business requirements, I played back end developer, full stack developer or lead developer roles in many .net stack projects. SharePoint Developer 8 years overall experience working with all versions of SharePoint. I can handle anything SharePoint. DotNetNuke Expert I am an expert dotnetnuke developer with more than 6 years of experience building large scale dnn based applications. I write about my leanings and experiences related to dotnetnuke and asp.net at TrickyCoder. I worked on dotnetnuke module development, dotnetnuke skinning, dotnetnuke migrations, dotnetnuke upgrades, catalook customization, dotnetnuke SEO, portal generation, scheduler development, news letters and almost all kind of development, customization and troubleshooting of DotNetNuke.

Updated on June 04, 2022

Comments

  • Prashant Lakhlani
    Prashant Lakhlani almost 2 years

    Can anybody suggest a tool or share code which can help me converting large number of t-sql stored procedures in database to postgresql while migrating from SQL Server database to postgresql?

    == Edited== here are some clear goals:

    1. Convert all sps to postgre sql without considering performance / tuning etc, by only focusing that syntax is right and query returns correct data

    Language conversion and transformation related guidelines are really useful. I see couple of old vbscript examples (most of them not working for me) and could try to convert them to T4 templates.

    I am surprised no one really needed this kind of conversion! I still don't have a right tool to do so.

    Thanks in advance.

  • Prashant Lakhlani
    Prashant Lakhlani over 12 years
    Yeah, none of them are useful for the sp conversion.
  • Jan Marek
    Jan Marek over 12 years
    I've found another document about converting from T-SQL to PostgreSQL, but this is not tool... :-(
  • Rob Kraft
    Rob Kraft over 6 years
    I don't think you will be able to find a tool because I don't believe it is possible. Our app supports several DBMSs. We write in T-SQL and it converts for Oracle PL/SQL, etc. But PostGreSQL functions are quite different and are not designed for returning the results of select queries. For example, it is a lot of work to have a function in PostGreSQL that simply returns the results of "Select * from TableA inner join TableB on A.ID=B.ID" because you need to specify every column in the return type of the function. Other DBMSs do not require that. We will probably not support PostGreSQL.
  • Ira Baxter
    Ira Baxter over 6 years
    Stored procedure languages are all Turing-capable AFAIK. That means one can compute anything the other can compute. So, it is possible. Granted, It might be lot of work, so much that in fact it isn't worth the effort, that's different than you can't do it. I build translators for a living. We've overcome most practical problems in ugly translations, so I'm a lot more optimistic than you are.