1

众所周知,SQL Server 提供了一些扩展机制,如用户定义的函数、存储过程、触发器......

我有在 SQL Server 2008 中运行的 C# 代码(它是使用 Visual Studio 2008 部署在 DBMS 中的存储过程,然后使用exec dbo.SP_Analysis 'MyTable','Colum1,Column2',300,0命令在 SQL Server 2008 中获取结果)定义为:

using System;
using System.Collections.Generic;
using System.Text;
using System.Security;
using System.Runtime.InteropServices;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;

public partial class StoredProcedures
{              
  [Microsoft.SqlServer.Server.SqlProcedure]
  public static void SP_Analysis(
     SqlString table, [SqlFacet(MaxSize = -1)] SqlString columns,
     int Nocustomers,
     Boolean result)
  {
     String query = "";

     using (SqlConnection conn = new SqlConnection("context connection=true"))
     {
        conn.Open();
        SqlCommand cmd = conn.CreateCommand();
        query = "SELECT " + (String)columns + " FROM " + (String)table + ";";
        cmd.CommandText = query;
        SqlDataReader reader = cmd.ExecuteReader();
        MyObject _myObject = new Object(Nocustomers);
        while (reader.Read())
           _myObject.read(reader);
        reader.Close();        
        conn.Close();
      } //END SqlConnection conn 
  }        
}

class MyObject
{
   int NoCustomers; 
   //some definitions

  public MyObject(int NoCustomers)
  {
     this.NoCustomers = NoCustomers;
     //some stuff
  }

   public void read(SqlDataReader reader)
   {
     Object[] record = new Object[NoCustomers];
     reader.GetValues(record);
     //more stuff
   }
}

很明显,我正在使用 .NET c# 可用语言,然后通过 Visual Studio 2008 部署它以在 SQL Server 2008 中创建存储过程。

现在我的问题是 Postgres 中所有这些的类比是什么?

  1. 可以使用什么语言来扩展 Postgres 的功能?
  2. 在 Postgres 中部署 UDF 与 Visual Studio 有何相似之处?
  3. exec dbo.UDFPostgres中的类比是什么?

我正在阅读 Postgres 使用 C 语言来定义 UDF,可能是 C++,但其他我不知道......

4

2 回答 2

5
  1. PL/Python、PL/Perl、PL/Java、PL/TCL、PL/V8 (JavaScript) 和 C 程序。但是,对于大多数工作,您只需使用 PL/PgSQL,这是用于过程的 SQL 的扩展版本。

  2. 一个都没有,真的。PgAdmin-III 之类的。您只需执行 SQL 命令来创建函数,或者在 C 过程的情况下,您可以使用带有 PGXS 的 Makefile

  3. 不知道,这在 SQL Server 中有什么作用?文档链接?如果只是“调用此程序”,那么SELECT my_function();.

于 2013-01-17T01:43:24.163 回答
1

PostgreSQL 支持。存储过程语言的数量,包括 PL/SQL 风格,一种基于 Perl,一种基于 Python,一种基于 Tcl。

PL/pgSQL 是一种直接嵌入 SQL 的块结构语言,与 Oracle 的 PL/SQL 非常相似。

于 2013-01-17T01:44:56.253 回答