1

I have my SQL function (database PostgreSQL):

CREATE OR REPLACE FUNCTION adduser(idTopic integer, name character varying, email character varying)
  RETURNS boolean AS
$BODY$
DECLARE checkName BOOLEAN;
    BEGIN

INSERT INTO Users (idTopic, name, email)
    VALUES (idTopic, name, email);

select (users.name=$2) into checkName from users where users.email = $3;

 return checkName;

    END;

$BODY$
  LANGUAGE plpgsql VOLATILE

And I can call this function from java:

@Override
  public void add(User user) {

  String queryAdd = "select adduser(" + user.getTopic().getId() + ",'" + user.getName() + "','" + user.getEmail() + "')";

        Query query = getCurrentSession().createSQLQuery(queryAdd);
        query.list();

  }

But I need to have query without word 'select', I need "adduser(idTopic, name, email)", How can I to do it?

3
  • 5
    This is fairly well documented. Commented May 15, 2014 at 9:17
  • 1
    @BoristheSpider though that link is to a very old version of the docs, in particular "PostgreSQL™ does not support functions that have output parameters" hasn't been accurate for ages. Commented May 15, 2014 at 11:32
  • 1
    I need call my SQL function from java-code by hibernate Commented May 15, 2014 at 12:20

1 Answer 1

1

Maybe?

do $$ begin perform adduser(idTopic, name, email); end; $$

Although I don't know much about java interfaces anymore, the above gives you a call to the function without using the word 'select'.

-g

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.