Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.65 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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