I'm using this function in PostgreSQL and it works but now I need to return multiple values, e.g.: _value
and _prefix
.
How can I do?
CREATE OR REPLACE FUNCTION generate_sequence(_account_id integer, _sequence text) RETURNS TEXT AS $$
DECLARE
_prefix text;
_next_value text;
_zero_pad integer;
_value text;
BEGIN
SELECT asq.prefix, asq.next_value::text, asq.zero_pad
INTO _prefix, _next_value, _zero_pad
FROM account_sequence asq
WHERE asq.account_id = _account_id
AND asq.sequence = _sequence;
_value := _prefix || _next_value;
IF _zero_pad IS NOT NULL THEN
_value := lpad(_value, _zero_pad, '0');
END IF;
UPDATE account_sequence SET
next_value = next_value + 1
WHERE account_id = _account_id
AND sequence = _sequence;
RETURN _value;
END;
$$ LANGUAGE plpgsql;