visual studio -类似于c# SQL Server´s存储过程CLR的Postgres

本文关键字:存储过程 CLR Postgres #180 studio 类似于 Server SQL visual | 更新日期: 2023-09-27 17:54:12

众所周知,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中类似的是什么?

    什么语言可以扩展Postgres的功能?
  1. 在Postgres中部署UDF的可能性与Visual Studio的类比是什么?
  2. 在Postgres中exec dbo.UDF的类似物是什么?

我读到Postgres使用C语言来定义udf,可能是c++

visual studio -类似于c# SQL Server´s存储过程CLR的Postgres

  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();

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

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