Re: [SQL] Using bind variable within BEGIN END - Mailing list pgsql-sql

From David G. Johnston
Subject Re: [SQL] Using bind variable within BEGIN END
Date
Msg-id CAKFQuwZYqwvo+yxZGb9U=iciN5wC_+F_aim8_kZDPqfTEbekpw@mail.gmail.com
Whole thread Raw
In response to [SQL] Using bind variable within BEGIN END  (anand086 <anand086@gmail.com>)
Responses Re: [SQL] Using bind variable within BEGIN END
List pgsql-sql
On Thu, Jun 1, 2017 at 5:24 PM, anand086 <anand086@gmail.com> wrote:
Hi,

I am quite new to postgresql and working with application team to migrate to
postgresql from oracle.

When we are trying to use bind variable within BEGIN/END code block, it
fails with

Caused by: java.sql.SQLException: The column index is out of range: 1,
number of columns: 0. Query: DO $do$ 
​ [...]​

What is the correct way to use bind variables in postgresql?

​CREATE FUNCTION func(arg1 text, arg2​ text) AS $$ SELECT arg1, arg2; $$ LANGUAGE sql; --or something like this

SELECT func(?, ?);

Explanation:

You cannot bind into a DO block because the content of the DO block is text and Java will not bind to question marks within text.  Creating a formal function and then calling it using a normal SELECT statement with binding positions - i.e., typical function execution - is thus required.

David J.

pgsql-sql by date:

Previous
From: anand086
Date:
Subject: [SQL] Using bind variable within BEGIN END
Next
From: Rob Sargent
Date:
Subject: Re: [SQL] Using bind variable within BEGIN END