pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedCall sql function in psql
4+ messages / 3 participants
[nested] [flat]
* Call sql function in psql
@ 2018-01-18 16:22 Abhra Kar <abhra.kar@gmail.com>
0 siblings, 2 replies; 4+ messages in thread
From: Abhra Kar @ 2018-01-18 16:22 UTC (permalink / raw)
To: pgsql-general
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.
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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Call sql function in psql
@ 2018-01-18 16:27 Rob Sargent <robjsargent@gmail.com>
parent: Abhra Kar <abhra.kar@gmail.com>
1 sibling, 0 replies; 4+ messages in thread
From: Rob Sargent @ 2018-01-18 16:27 UTC (permalink / raw)
To: Abhra Kar <abhra.kar@gmail.com>; +Cc: pgsql-general
> On Jan 18, 2018, at 9:22 AM, Abhra Kar <abhra.kar@gmail.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).
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Call sql function in psql
@ 2018-01-18 16:31 David G. Johnston <david.g.johnston@gmail.com>
parent: Abhra Kar <abhra.kar@gmail.com>
1 sibling, 1 reply; 4+ messages in thread
From: David G. Johnston @ 2018-01-18 16:31 UTC (permalink / raw)
To: Abhra Kar <abhra.kar@gmail.com>; +Cc: pgsql-general
On Thu, Jan 18, 2018 at 9:22 AM, Abhra Kar <abhra.kar@gmail.com> wrote:
>
> I tried to modify like
>
>
>
> sess.createSQLQuery("select reset_all()")
>
This part is correct
> .executeUpdate();
>
>
>
> getting error -- org.postgresql.util.PSQLException: A result was returned
> when none was expected.
>
>
>
You need execute the above the same way you would execute "SELECT * FROM
tbl"; then just ignore the result set that is returned.
David J.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Call sql function in psql
@ 2018-01-19 06:58 Abhra Kar <abhra.kar@gmail.com>
parent: David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 0 replies; 4+ messages in thread
From: Abhra Kar @ 2018-01-19 06:58 UTC (permalink / raw)
To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: pgsql-general
Thanks
On Thu, Jan 18, 2018 at 10:01 PM, David G. Johnston <
david.g.johnston@gmail.com> wrote:
> On Thu, Jan 18, 2018 at 9:22 AM, Abhra Kar <abhra.kar@gmail.com> wrote:
>
>>
>> I tried to modify like
>>
>>
>>
>> sess.createSQLQuery("select reset_all()")
>>
>
> This part is correct
>
>
>
>> .executeUpdate();
>>
>>
>>
>> getting error -- org.postgresql.util.PSQLException: A result was
>> returned when none was expected.
>>
>>
>>
> You need execute the above the same way you would execute "SELECT * FROM
> tbl"; then just ignore the result set that is returned.
>
> David J.
>
>
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2018-01-19 06:58 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-01-18 16:22 Call sql function in psql Abhra Kar <abhra.kar@gmail.com>
2018-01-18 16:27 ` Rob Sargent <robjsargent@gmail.com>
2018-01-18 16:31 ` David G. Johnston <david.g.johnston@gmail.com>
2018-01-19 06:58 ` Abhra Kar <abhra.kar@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox