agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFunction with OUT parameter and Return Query
3+ messages / 2 participants
[nested] [flat]
* Function with OUT parameter and Return Query
@ 2014-10-05 04:23 Hector Menchaca <hm34306@hotmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Hector Menchaca @ 2014-10-05 04:23 UTC (permalink / raw)
To: pgsql-sql
All,Struggling tying to get a function that works in Maraidb stored procs...looking to return an OUT Parameter value with Return Query
CREATE FUNCTION sp_AgentServer_Register (_agentserver_name TEXT, _port INTEGER, out _out_agent_server_id INTEGER) RETURNS SETOF AgentServerAS $$BEGIN Select _agent_server_id INTO _out_agent_server_id FROM sp_private_AgentServer_Insert(_agentserver_name, _port);
Update AgentServer SET RegisteredOn = NOW() where AgentServer_ID = _out_agent_server_id;
RETURN QUERY Select * From AgentServer where AgentServer_ID = _out_agent_server_id; END$$ LANGUAGE plpgsql;
In doing this an error is returned :ERROR: function result type must be integer because of OUT parameters
If I change to Integer, then I get an Error From the return query...ERROR: cannot use RETURN QUERY in a non-SETOF function
Is there a way to do this? (I'm assuming no at this point... i hoping there is some flag or something that I can set...)I can do this with MariaDB and SqlServer...
Any thoughts are appreciated.
=
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Function with OUT parameter and Return Query
@ 2014-10-05 08:06 Guillaume Lelarge <guillaume@lelarge.info>
parent: Hector Menchaca <hm34306@hotmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Guillaume Lelarge @ 2014-10-05 08:06 UTC (permalink / raw)
To: Hector Menchaca <hm34306@hotmail.com>; +Cc: pgsql-sql
Hi,
2014-10-05 6:23 GMT+02:00 Hector Menchaca <hm34306@hotmail.com>:
> All,
> Struggling tying to get a function that works in Maraidb stored procs...
> looking to return an OUT Parameter value with Return Query
>
> CREATE FUNCTION sp_AgentServer_Register (_agentserver_name TEXT, _port
> INTEGER, out _out_agent_server_id INTEGER)
> RETURNS SETOF AgentServer
> AS $$
> BEGIN
> Select _agent_server_id INTO _out_agent_server_id FROM
> sp_private_AgentServer_Insert(_agentserver_name, _port);
>
> Update AgentServer
> SET RegisteredOn = NOW()
> where AgentServer_ID = _out_agent_server_id;
>
> RETURN QUERY
> Select * From AgentServer where AgentServer_ID = _out_agent_server_id;
> END$$ LANGUAGE plpgsql;
>
> In doing this an error is returned :
> ERROR: function result type must be integer because of OUT parameters
>
> If I change to Integer, then I get an Error From the return query...
> ERROR: cannot use RETURN QUERY in a non-SETOF function
>
> Is there a way to do this? (I'm assuming no at this point... i hoping
> there is some flag or something that I can set...)
> I can do this with MariaDB and SqlServer...
>
>
In the above function, you don't need the ", out _out_agent_server_id
INTEGER" because you already have it in the AgentServer record it sends
back. So get rid of it, and it should work.
--
Guillaume.
http://blog.guillaume.lelarge.info
http://www.dalibo.com
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Function with OUT parameter and Return Query
@ 2014-10-05 18:10 Hector Menchaca <hm34306@hotmail.com>
parent: Guillaume Lelarge <guillaume@lelarge.info>
0 siblings, 0 replies; 3+ messages in thread
From: Hector Menchaca @ 2014-10-05 18:10 UTC (permalink / raw)
To: Guillaume Lelarge <guillaume@lelarge.info>; +Cc: pgsql-sql
Correct... in this case that wold suffice...
thanks
Date: Sun, 5 Oct 2014 10:06:04 +0200
Subject: Re: [SQL] Function with OUT parameter and Return Query
From: guillaume@lelarge.info
To: hm34306@hotmail.com
CC: pgsql-sql@postgresql.org
Hi,
2014-10-05 6:23 GMT+02:00 Hector Menchaca <hm34306@hotmail.com>:
All,Struggling tying to get a function that works in Maraidb stored procs...looking to return an OUT Parameter value with Return Query
CREATE FUNCTION sp_AgentServer_Register (_agentserver_name TEXT, _port INTEGER, out _out_agent_server_id INTEGER) RETURNS SETOF AgentServerAS $$BEGIN Select _agent_server_id INTO _out_agent_server_id FROM sp_private_AgentServer_Insert(_agentserver_name, _port);
Update AgentServer SET RegisteredOn = NOW() where AgentServer_ID = _out_agent_server_id;
RETURN QUERY Select * From AgentServer where AgentServer_ID = _out_agent_server_id; END$$ LANGUAGE plpgsql;
In doing this an error is returned :ERROR: function result type must be integer because of OUT parameters
If I change to Integer, then I get an Error From the return query...ERROR: cannot use RETURN QUERY in a non-SETOF function
Is there a way to do this? (I'm assuming no at this point... i hoping there is some flag or something that I can set...)I can do this with MariaDB and SqlServer...
In the above function, you don't need the ", out _out_agent_server_id INTEGER" because you already have it in the AgentServer record it sends back. So get rid of it, and it should work.
--
Guillaume.
http://blog.guillaume.lelarge.info
http://www.dalibo.com
=
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2014-10-05 18:10 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-10-05 04:23 Function with OUT parameter and Return Query Hector Menchaca <hm34306@hotmail.com>
2014-10-05 08:06 ` Guillaume Lelarge <guillaume@lelarge.info>
2014-10-05 18:10 ` Hector Menchaca <hm34306@hotmail.com>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox