views:

31

answers:

1

Hi,

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  A: 

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.

Martin Smith