4

Im feeling crazy and I've decided I would really like to write a User-Defined Function in Python that would run in SQL Server 2008. I am interested in doing this as I have a few thousand lines of PL/Python functions written for PostgreSQL and I am interested to know if I can get the project running on SQL Server instead.

I am looking at IronPython for the first time trying to work out if I can convert something like this C#...

using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;

public partial class UserDefinedFunctions
{
    [Microsoft.SqlServer.Server.SqlFunction]
    public static SqlString Function1()
    {
        // Put your code here
        return new SqlString("Hello");
    }
};

... into Python.

Has anyone got any ideas on this one? Is it possible?

The bit I am particularly perplexed by is the annotation:

[Microsoft.SqlServer.Server.SqlFunction]

How do I write that in Python? Looks a bit like a decorator :)

All suggestions welcome.

Cheers, Tom

1 Answer 1

2

According to this article you're wasting your time trying. Apparently you simply can't use dynamic languages in SQL CLR even in UNSAFE assemblies.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.