如何在postgresql中编写函数? [英] How to write function in postgresql?
问题描述
大家好,
我想知道如何使用postgresql中的输出参数来编写函数。
这是我的表演员结构,包含数据和数据类型。
actorid | fistname | lastname | last_update |
整数|字符|字符|时间戳|
1;Penelope;Guiness;2013-05-26 14:47:57.62
2;Nick;Wahlberg;2013-05-26 14:47:57.62
我有什么试过:
我写了一个函数来从查询中使用out关键字获取结果集。
创建或替换函数view_setactor(id int,out first_name TEXT,lastname TEXT)
返回setof记录
as
$$
选择*来自演员,其中actor_id = $ 1;
$$
语言''sql''稳定;
但是我收到错误..
错误:功能结果由于OUT参数,类型必须是文本
**********错误**********
错误:由于OUT参数,函数结果类型必须是文本
SQL状态:42P13
这个请求对我的帮助是什么...非常感谢任何解决方案。
Hi All,
I want to know how to write function using output parameter in postgresql.
this is my table actor structure with data and datatype.
actorid|fistname |lastname| last_update|
integer|character|character|timestamp|
1;"Penelope";"Guiness";"2013-05-26 14:47:57.62"
2;"Nick";"Wahlberg";"2013-05-26 14:47:57.62"
What I have tried:
I have written one function to get result set from the query using out keyword in function.
create or replace function view_setactor(id int,out first_name TEXT,lastname TEXT)
returns setof record
as
$$
select * from actor where actor_id=$1;
$$
language ''sql'' STABLE;
but iam getting error..
ERROR: function result type must be text because of OUT parameters
********** Error **********
ERROR: function result type must be text because of OUT parameters
SQL state: 42P13
what is this pleas help me on this..any solution would be greatly appreciated.
推荐答案
从演员中选择*,其中actor_id =
select * from actor where actor_id=
1;
1;
language's'ql''STABLE;
但是我收到错误..
错误:功能结果由于OUT参数,类型必须是文本
**********错误**********
错误:由于OUT参数,函数结果类型必须是文本
SQL状态:42P13
这个请求对我有什么帮助...非常感谢任何解决方案。
language ''sql'' STABLE;
but iam getting error..
ERROR: function result type must be text because of OUT parameters
********** Error **********
ERROR: function result type must be text because of OUT parameters
SQL state: 42P13
what is this pleas help me on this..any solution would be greatly appreciated.
这篇关于如何在postgresql中编写函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!