SQLCLR&铁蟒

发布于 2024-09-14 09:15:50 字数 753 浏览 1 评论 0原文

我感觉很疯狂,我决定我真的很想用 Python 编写一个可以在 SQL Server 2008 中运行的用户定义函数。我对此很感兴趣,因为我有几千行为 PostgreSQL 编写的 PL/Python 函数我很想知道是否可以让该项目在 SQL Server 上运行。

我第一次查看 IronPython,试图弄清楚是否可以将 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");
    }
};

... 之类的东西转换为 Python。

有人对此有任何想法吗?是否可以?

我特别困惑的是注释:

[Microsoft.SqlServer.Server.SqlFunction]

How do I write that in Python?看起来有点像装饰器:)

欢迎所有建议。

干杯, 汤姆

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九八野马 2024-09-21 09:15:50

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文