user2664380
user2664380

Reputation: 289

function which returns as hstore datatype in postgresql

"hstoredata" is a variable of type hstore which contains key value pairs.

i.e. for ex: "hstoredata" variable contains the key value pairs '"ed"=>"1", "id"=>"1", "age"=>"27"'.

If "hstoredata" variable is passed to the function i.e select sampletest(hstoredata), function is returning as null.

-- Function: sampletest(hstore)

-- DROP FUNCTION sampletest(hstore)

CREATE OR REPLACE FUNCTION sampletest(hstoredata hstore)    
RETURNS SETOF void AS    
$BODY$     
DECLARE   
newhstoredata hstore;    
BEGIN    
    newhstoredata := samplehstore(hstoredata);    
    RAISE NOTICE 'newhstoredata: %', newhstoredata;    
END;    
$BODY$    
  LANGUAGE plpgsql VOLATILE    
  COST 100    
  ROWS 1000;    
ALTER FUNCTION sampletest(hstore)   
  OWNER TO postgres;

Below is the program for function samplehstore(hstore)

-- Function: samplehstore(hstore)

-- DROP FUNCTION samplehstore(hstore)

CREATE OR REPLACE FUNCTION samplehstore(hstoredata hstore)    
RETURNS SETOF void AS    
$BODY$     
BEGIN       
    RAISE NOTICE 'hstoredata: %', hstoredata;    
END;   
$BODY$    
LANGUAGE plpgsql VOLATILE    
COST 100
ROWS 1000;
ALTER FUNCTION samplehstore(hstore)
OWNER TO postgres;

Upvotes: 0

Views: 524

Answers (1)

Denis de Bernardy
Denis de Bernardy

Reputation: 78443

It's unclear what you're asking precisely, but based on the title, I assume you'd like your function to return something.

If so, the issue here is that you're declaring your function as returning setof void.

Declare it as returning whatever it should, and use return ... or return query ..., depending on what you actually need.

Upvotes: 1

Related Questions