Revision 6271
Added by Aaron Marcuse-Kubitza about 12 years ago
schemas/functions.sql | ||
---|---|---|
146 | 146 |
LANGUAGE plpgsql IMMUTABLE |
147 | 147 |
AS $$ |
148 | 148 |
DECLARE |
149 |
map hstore := '*' => '!' || map; -- set default value for '*' |
|
150 |
match text := COALESCE(map -> value, map -> '*'); |
|
149 |
match text := map -> value; |
|
151 | 150 |
BEGIN |
151 |
IF match IS NULL AND NOT map ? value THEN -- no match rather than NULL match |
|
152 |
match := map -> '*'; -- use default entry |
|
153 |
IF match IS NULL AND NOT map ? '*' THEN match := '!'; -- no default |
|
154 |
END IF; |
|
155 |
END IF; |
|
156 |
|
|
157 |
-- Interpret result |
|
152 | 158 |
IF match = '!' THEN RAISE 'Value not in map: %', value USING ERRCODE = 'data_exception'; |
153 | 159 |
ELSIF match = '*' THEN RETURN value; |
154 | 160 |
ELSE RETURN match; |
Also available in: Unified diff
schemas/functions.sql: _map(): Fixed bug where entries that map to NULL were incorrectly being treated as if the entry didn't exist. Note that -> returns NULL both if the entry's value is NULL and if the entry doesn't exist, so ? must be used to recheck the presence of the key in the hstore.