Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
06fb6105
Commit
06fb6105
authored
Apr 01, 2005
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make plperl work with OUT parameters.
parent
943178fe
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
19 deletions
+90
-19
src/pl/plperl/plperl.c
src/pl/plperl/plperl.c
+12
-19
src/pl/plperl/test/test.expected
src/pl/plperl/test/test.expected
+55
-0
src/pl/plperl/test/test_queries.sql
src/pl/plperl/test/test_queries.sql
+23
-0
No files found.
src/pl/plperl/plperl.c
View file @
06fb6105
...
...
@@ -33,7 +33,7 @@
* ENHANCEMENTS, OR MODIFICATIONS.
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.7
0 2005/03/29 00:17:20
tgl Exp $
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.7
1 2005/04/01 19:34:06
tgl Exp $
*
**********************************************************************/
...
...
@@ -409,21 +409,16 @@ plperl_trigger_build_args(FunctionCallInfo fcinfo)
* NB: copy the result if needed for any great length of time
*/
static
TupleDesc
get_function_tupdesc
(
Oid
result_type
,
ReturnSetInfo
*
rs
info
)
get_function_tupdesc
(
FunctionCallInfo
fc
info
)
{
if
(
result_type
==
RECORDOID
)
{
/* We must get the information from call context */
if
(
!
rsinfo
||
!
IsA
(
rsinfo
,
ReturnSetInfo
)
||
rsinfo
->
expectedDesc
==
NULL
)
TupleDesc
result
;
if
(
get_call_result_type
(
fcinfo
,
NULL
,
&
result
)
!=
TYPEFUNC_COMPOSITE
)
ereport
(
ERROR
,
(
errcode
(
ERRCODE_FEATURE_NOT_SUPPORTED
),
errmsg
(
"function returning record called in context "
"that cannot accept type record"
)));
return
rsinfo
->
expectedDesc
;
}
else
/* ordinary composite type */
return
lookup_rowtype_tupdesc
(
result_type
,
-
1
);
return
result
;
}
/**********************************************************************
...
...
@@ -897,8 +892,7 @@ plperl_func_handler(PG_FUNCTION_ARGS)
/* Cache a copy of the result's tupdesc and attinmeta */
oldcontext
=
MemoryContextSwitchTo
(
funcctx
->
multi_call_memory_ctx
);
tupdesc
=
get_function_tupdesc
(
prodesc
->
result_oid
,
(
ReturnSetInfo
*
)
fcinfo
->
resultinfo
);
tupdesc
=
get_function_tupdesc
(
fcinfo
);
tupdesc
=
CreateTupleDescCopy
(
tupdesc
);
funcctx
->
attinmeta
=
TupleDescGetAttInMetadata
(
tupdesc
);
MemoryContextSwitchTo
(
oldcontext
);
...
...
@@ -1003,8 +997,7 @@ plperl_func_handler(PG_FUNCTION_ARGS)
/*
* XXX should cache the attinmeta data instead of recomputing
*/
td
=
get_function_tupdesc
(
prodesc
->
result_oid
,
(
ReturnSetInfo
*
)
fcinfo
->
resultinfo
);
td
=
get_function_tupdesc
(
fcinfo
);
/* td = CreateTupleDescCopy(td); */
attinmeta
=
TupleDescGetAttInMetadata
(
td
);
...
...
src/pl/plperl/test/test.expected
View file @
06fb6105
...
...
@@ -222,6 +222,61 @@ SELECT * FROM perl_record_set() AS (f1 integer, f2 text, f3 text);
3 | Hello | PL/Perl
(3 rows)
CREATE OR REPLACE FUNCTION
perl_out_params(f1 out integer, f2 out text, f3 out text) AS $$
return {f2 => 'hello', f1 => 1, f3 => 'world'};
$$ LANGUAGE plperl;
SELECT perl_out_params();
perl_out_params
-----------------
(1,hello,world)
(1 row)
SELECT * FROM perl_out_params();
f1 | f2 | f3
----+-------+-------
1 | hello | world
(1 row)
SELECT (perl_out_params()).f2;
f2
-------
hello
(1 row)
CREATE OR REPLACE FUNCTION
perl_out_params_set(out f1 integer, out f2 text, out f3 text)
RETURNS SETOF record AS $$
return [
{ f1 => 1, f2 => 'Hello', f3 => 'World' },
{ f1 => 2, f2 => 'Hello', f3 => 'PostgreSQL' },
{ f1 => 3, f2 => 'Hello', f3 => 'PL/Perl' }
];
$$ LANGUAGE plperl;
SELECT perl_out_params_set();
perl_out_params_set
----------------------
(1,Hello,World)
(2,Hello,PostgreSQL)
(3,Hello,PL/Perl)
(3 rows)
SELECT * FROM perl_out_params_set();
f1 | f2 | f3
----+-------+------------
1 | Hello | World
2 | Hello | PostgreSQL
3 | Hello | PL/Perl
(3 rows)
SELECT (perl_out_params_set()).f3;
f3
------------
World
PostgreSQL
PL/Perl
(3 rows)
CREATE TYPE footype AS (x INTEGER, y INTEGER);
CREATE OR REPLACE FUNCTION foo_good() RETURNS SETOF footype AS $$
return [
...
...
src/pl/plperl/test/test_queries.sql
View file @
06fb6105
...
...
@@ -135,6 +135,29 @@ SELECT perl_record_set();
SELECT
*
FROM
perl_record_set
();
SELECT
*
FROM
perl_record_set
()
AS
(
f1
integer
,
f2
text
,
f3
text
);
CREATE
OR
REPLACE
FUNCTION
perl_out_params
(
f1
out
integer
,
f2
out
text
,
f3
out
text
)
AS
$$
return
{
f2
=>
'hello'
,
f1
=>
1
,
f3
=>
'world'
}
;
$$
LANGUAGE
plperl
;
SELECT
perl_out_params
();
SELECT
*
FROM
perl_out_params
();
SELECT
(
perl_out_params
()).
f2
;
CREATE
OR
REPLACE
FUNCTION
perl_out_params_set
(
out
f1
integer
,
out
f2
text
,
out
f3
text
)
RETURNS
SETOF
record
AS
$$
return
[
{
f1
=>
1
,
f2
=>
'Hello'
,
f3
=>
'World'
}
,
{
f1
=>
2
,
f2
=>
'Hello'
,
f3
=>
'PostgreSQL'
}
,
{
f1
=>
3
,
f2
=>
'Hello'
,
f3
=>
'PL/Perl'
}
];
$$
LANGUAGE
plperl
;
SELECT
perl_out_params_set
();
SELECT
*
FROM
perl_out_params_set
();
SELECT
(
perl_out_params_set
()).
f3
;
--
-- Check behavior with erroneous return values
--
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment