Last active
August 29, 2015 14:22
-
-
Save robshep/d8e803759392ea2d2fa2 to your computer and use it in GitHub Desktop.
Build an HStore-based query index for EAV attributes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE OR REPLACE FUNCTION delete_thing_att_map_hstore() | |
| RETURNS trigger AS | |
| $BODY$BEGIN | |
| update | |
| thing | |
| set | |
| att_map = ( att_map - OLD.def_id::text ) | |
| WHERE | |
| id = NEW.thing_id; | |
| RETURN NEW; | |
| END;$BODY$ | |
| LANGUAGE plpgsql VOLATILE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE OR REPLACE FUNCTION update_thing_att_map_hstore() | |
| RETURNS trigger AS | |
| $BODY$BEGIN | |
| update | |
| thing | |
| set | |
| att_map = coalesce(att_map, hstore(array[]::varchar[])) | |
| || | |
| hstore(NEW.def_id::text, NEW.value::text) | |
| WHERE | |
| id = NEW.thing_id; | |
| RETURN NEW; | |
| END;$BODY$ | |
| LANGUAGE plpgsql VOLATILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment