I am trying to write some postgresql functions to help me parse a string value like "30Gi" or "25Ti". I tried this, but can't get the syntax right, and can't figure out what the return type should be for the first function.
CREATE FUNCTION get_matches(VARCHAR) RETURNS ARRAY(VARCHAR) AS
SELECT (regexp_matches ($1, '(\d+)([KGTM]i)'));
CREATE FUNCTION get_amount(ARRAY(VARCHAR)) RETURNS VARCHAR AS
SELECT get_matches($1)[1];
CREATE FUNCTION get_units(ARRAY(VARCHAR)) RETURNS VARCHAR AS
SELECT get_matches($1)[2];
Postgres version:
PostgreSQL 13.2 on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
Testing my functions using pgAdmin4.