Postgresql 中的表值参数等效项 [英] Table valued Parameter Equivalent in Postgresql
本文介绍了Postgresql 中的表值参数等效项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 postgresql 中 - 什么是带有表值参数的存储过程(MSSQL)?
In postgresql- what is the equivalent of stored procedure with table valued paramater(MSSQL)?
推荐答案
@HamidKhan - 你的开发语言是 Java 还是 C#?
@HamidKhan -Is your development language Java or C #?
CREATE TABLE public.employee (
emp_id INTEGER NOT NULL,
emp_nm VARCHAR(40),
first_in_time TIMESTAMP WITH TIME ZONE DEFAULT clock_timestamp(),
last_chg_time TIMESTAMP WITH TIME ZONE DEFAULT clock_timestamp(),
CONSTRAINT employee_pkey PRIMARY KEY(emp_id)
)
WITH (oids = false);
CREATE TYPE public.employee_udt AS (
emp_id INTEGER,
emp_nm VARCHAR(40)
);
--c# 代码 1
public class EmployeeUdt
{
[PgName("emp_id")]
public int EmpId { get; set; }
[PgName("emp_nm")]
public string EmpNm { get; set; }
}
--c# 代码 2
List<EmployeeUdt> lst_param = new List<EmployeeUdt>();
for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
{
lst_param.Add(
new EmployeeUdt
{
EmpId = Convert.ToInt32(this.dataGridView1[0, i].Value),
EmpNm = this.dataGridView1[1, i].Value.ToString()
}
);
}
var _param = new[] {
new NpgsqlParameter
{
ParameterName="p_employee",
NpgsqlDbType = NpgsqlDbType.Composite,
SpecificType = typeof(EmployeeUdt[]),
NpgsqlValue = lst_param
}
};
SqlHelper.ExecuteNonQuery<EmployeeUdt>(this.connstring, "usp_set_emp", _param);
这篇关于Postgresql 中的表值参数等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文