Custom Range, base data types and PostgreSQL binary data
//UUID and text are avaiable subtypes but are not quantifiable
//This is the structure of a CREATE TYPE range
//The [,] is for optional fields while | is for optional values
CREATE TYPE name AS RANGE (
SUBTYPE = subtype
[ , SUBTYPE_OPCLASS = subtype_operator_class ]
[ , COLLATION = collation ]
[ , CANONICAL = canonical_function ]
[ , SUBTYPE_DIFF = subtype_diff_function ]
[ , MULTIRANGE_TYPE_NAME = multirange_type_name ]
)//DO anonymous blocks can't issue a RETURN statement
//The %ROWTYPE variable requires an entire table row, not a single column
CREATE TYPE durate AS RANGE (
SUBTYPE = interval
);
CREATE TABLE igno (
sensor_id SERIAL PRIMARY KEY, time_window durate
);
INSERT INTO igno (time_window) VALUES
('[0.5 hours, 5 hours)'::durate), ('[5 hours, 15 hours)'::durate);
DO $$
declare
--linea igno%ROWTYPE; //Select * from ...
linea durate; //Select time_window from ...
begin
SELECT time_window INTO linea from igno where sensor_id = 2;
RAISE NOTICE 'We found the %', linea;
IF (linea) @> '10 hours'::interval THEN
RAISE NOTICE 'within the interval range';
ELSE
RAISE NOTICE 'outside the interval';
END IF;
--RETURN 'The inteval being "'|| linea ||'" '; //Error
end;
$$ language PLPGSQL;
//We found the [05:00:00,15:00:00)
//within the interval rangePostgreSQL base custom data type
PostgreSQL binary data storage and SQL standard syntax.
Last updated