Dblink vs calling a function that returns void

Started by Boszormenyi Zoltanabout 16 years ago4 messagesgeneral
Jump to latest
#1Boszormenyi Zoltan
zb@cybertec.at

Hi,

I need to call a function via dblink that returns a void, i.e.
technically nothing.

=# select public.dblink_exec('import', 'SELECT
import.add_one_word(''word'', true)');
ERROR: statement returning results not allowed

=# select * from public.dblink('import', 'SELECT
import.add_one_word(''word'', true)') as x();
ERROR: syntax error at or near ")"
LINE 1: ...ort', 'SELECT import.add_one_word(''iphon'', true)') as x();

=# select public.dblink('import', 'SELECT import.add_one_word(''word'',
true)') as x(x void);
ERROR: syntax error at or near "("
LINE 1: ...'SELECT import.add_one_word(''iphon'', true)') as x(x void);

And, although RETURNS VOID is indistinguishable from returning a NULL:

=# select * from public.dblink('import', 'SELECT
import.add_one_word(''word'', true)') as x(x int);
ERROR: invalid input syntax for integer: ""

So, how can I do it? Besides modifying the interface of the function,
say "RETURNS int4" and using PG_RETURN_NULL()?

Best regards,
Zolt�n B�sz�rm�nyi

--
Bible has answers for everything. Proof:
"But let your communication be, Yea, yea; Nay, nay: for whatsoever is more
than these cometh of evil." (Matthew 5:37) - basics of digital technology.
"May your kingdom come" - superficial description of plate tectonics

----------------------------------
Zolt�n B�sz�rm�nyi
Cybertec Sch�nig & Sch�nig GmbH
http://www.postgresql.at/

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Boszormenyi Zoltan (#1)
Re: Dblink vs calling a function that returns void

Boszormenyi Zoltan <zb@cybertec.at> writes:

I need to call a function via dblink that returns a void, i.e.
technically nothing.

You're overthinking the problem. Imagine void is just a datatype
(which it is...) This should work:

select * from public.dblink('import', 'SELECT import.add_one_word(''word'', true)') as x(x void);

regards, tom lane

#3Merlin Moncure
mmoncure@gmail.com
In reply to: Tom Lane (#2)
Re: Dblink vs calling a function that returns void

On Mon, Mar 29, 2010 at 12:12 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Boszormenyi Zoltan <zb@cybertec.at> writes:

I need to call a function via dblink that returns a void, i.e.
technically nothing.

You're overthinking the problem.  Imagine void is just a datatype
(which it is...)  This should work:

but it isn't! void returning functions may not be queried over the
binary protocol (why?), so if you used dblink w/void returning
functions, and dblink later supported binary results, your code would
break (i'm sure such a thing would be optional, but the point stands).

merlin

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Merlin Moncure (#3)
Re: Dblink vs calling a function that returns void

Merlin Moncure <mmoncure@gmail.com> writes:

You're overthinking the problem. �Imagine void is just a datatype
(which it is...) �This should work:

but it isn't! void returning functions may not be queried over the
binary protocol (why?),

Probably because we never made a send function for type void. Might
be worth fixing someday.

regards, tom lane