Guest User

Untitled

a guest
May 7th, 2012
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. storing varying data types in a (postgresql) database
  2. CREATE TABLE key_values(user_id integer references users(id), key varchar(255), type varchar(255), CONSTRAINT UNIQUE(user_id, key));
  3. CREATE TABLE key_values_int(value integer) INHERITS (key_values);
  4. CREATE TABLE key_values_string(value varchar(255)) INHERITS (key_values);
  5. and so on...
  6.  
  7. CREATE INDEX tbl_col_propx_idx ON tbl (cast(col AS int))
  8. WHERE prop_type_id = 23; -- 23 signifying "propertyX"
  9.  
  10. CREATE TABLE prop_type(
  11. prop_type_id int PRIMARY KEY,
  12. prop_type text NOT NULL);
  13.  
  14. SELECT *
  15. FROM tbl
  16. WHERE prop_type_id = 23 -- 23 signifying "propertyX"
  17. AND col::int BETWEEN 50 AND 100
Advertisement
Add Comment
Please, Sign In to add comment