Re: Call sql function in psql

From: Rob Sargent <robjsargent(at)gmail(dot)com>
To: Abhra Kar <abhra(dot)kar(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Call sql function in psql
Date: 2018-01-18 16:27:21
Message-ID: 88C8D539-67F2-472C-AA5F-5F6F274DBA84@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


> On Jan 18, 2018, at 9:22 AM, Abhra Kar <abhra(dot)kar(at)gmail(dot)com> wrote:
>
> Hi All,
>
> Please send me some info how to post directly in mailing list,somwhow I am not able to find out the way so I am mailing here.
>
>
Here is fine

>
> Present problem--
>
>
>
> I tried to change below code in psql —
>
>
> Session sess = (Session) entityManager.getDelegate();
>
> sess.createSQLQuery("{ call reset_all() }").executeUpdate();
>
>
> Here 'sess' is org.hibernate.Session and reset_all() is a function which contains—
>
>
> DECLARE
>
> username varchar(30);
>
> BEGIN
>
> select user into username;
>
> if username like 'XXXXX%' then
>
> update YYYYY set aaaa = 0;
>
> update ZZZZ set bbbb= 0;
>
> EXECUTE('truncate table abc');
>
> EXECUTE('truncate table def');
>
> ::::::::::::::::::::::::::::::::::::::::::::::::
>
> else
>
> RAISE NOTICE 'User not allowed to run this procedure';
>
> end if;
>
> end;
>
>
> I tried to modify like
>
>
> sess.createSQLQuery("select reset_all()").executeUpdate();
>
>
> getting error -- org.postgresql.util.PSQLException: A result was returned when none was expected.
>
>
> What should be the syntax of calling reset_all().
>
>
>
> Thanks and Regards,
>
> Abhra
>
>
>
At the very least change ‘call’ to ‘select’. Are those braces (“{}”) truly necessary? (Been a while since I’ve user hibernate).

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2018-01-18 16:31:17 Re: Call sql function in psql
Previous Message Abhra Kar 2018-01-18 16:22:32 Call sql function in psql