stds_tables_template.sql 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. --#############################################################################
  2. -- This SQL script generates the space time dataset tables to store time
  3. -- stamps and revision for SQL queries and temporal GIS support.
  4. --
  5. -- Author: Soeren Gebbert soerengebbert <at> googlemail <dot> com
  6. --#############################################################################
  7. -- STDS is a placeholder for specific space-time dataset type: strds, str3ds, stvds
  8. --PRAGMA foreign_keys = ON;
  9. CREATE TABLE STDS_base (
  10. id VARCHAR NOT NULL, -- Id of the space-time dataset, name@mapset this is the primary key
  11. name VARCHAR NOT NULL, -- name of the space-time dataset
  12. mapset VARCHAR NOT NULL, -- mapset of the space-time dataset
  13. creator VARCHAR NOT NULL, -- Name of the creator
  14. temporal_type VARCHAR NOT NULL, -- The temporal type of the dataset "absolute" or "relative"
  15. semantic_type VARCHAR NOT NULL, -- The semantic data description used for aggregation/decomposition algorithm selection: min, max, mean or sum
  16. creation_time TIMESTAMP NOT NULL, -- The time of creation of the space-time dataset
  17. -- Uncommented due to performance issues
  18. -- modification_time TIMESTAMP NOT NULL, -- The time of the last modification of the grass map
  19. -- revision SMALLINT NOT NULL, -- The revision number -- The revision number
  20. PRIMARY KEY (id)
  21. );
  22. CREATE TABLE STDS_relative_time (
  23. id VARCHAR NOT NULL, -- Id of the space-time dataset, this is the primary foreign key
  24. start_time INTEGER, -- The relative valid start time
  25. end_time INTEGER, -- The relative valid end time
  26. granularity INTEGER, -- The granularity
  27. unit VARCHAR, -- The relative time unit, available are "years, months, days, minutes, seconds"
  28. map_time VARCHAR, -- The temporal type of the registered maps, may be interval, point or mixed
  29. PRIMARY KEY (id),
  30. FOREIGN KEY (id) REFERENCES STDS_base (id) ON DELETE CASCADE
  31. );
  32. CREATE TABLE STDS_absolute_time (
  33. id VARCHAR NOT NULL, -- Id of the space-time dataset, this is the primary foreign key
  34. start_time TIMESTAMP, -- Start of the valid time, can be NULL if no map is registered
  35. end_time TIMESTAMP, -- End of the valid time, can be NULL if no map is registered
  36. granularity VARCHAR, -- The granularity "NNN seconds, NNN minutes, NNN hours, NNN days, NNN months, NNN years"
  37. timezone VARCHAR, -- The timezone of the valid time stored as string. This is currently not in use. Instead the timezone is set in the datetime strings
  38. map_time VARCHAR, -- The temporal type of the registered maps, may be interval, point or mixed
  39. PRIMARY KEY (id),
  40. FOREIGN KEY (id) REFERENCES STDS_base (id) ON DELETE CASCADE
  41. );
  42. CREATE TABLE STDS_spatial_extent (
  43. id VARCHAR NOT NULL, -- Id of the space-time dataset, this is the primary foreign key
  44. north DOUBLE PRECISION, -- The spatial north extent, derived from the registered maps
  45. south DOUBLE PRECISION, -- The spatial south extent, derived from the registered maps
  46. east DOUBLE PRECISION, -- The spatial east extent, derived from the registered maps
  47. west DOUBLE PRECISION, -- The spatial west extent, derived from the registered maps
  48. top DOUBLE PRECISION, -- The spatial top extent, derived from the registered maps
  49. bottom DOUBLE PRECISION, -- The spatial bottom extent, derived from the registered maps
  50. proj VARCHAR, -- The projection of the space time dataset (XY of LL)
  51. PRIMARY KEY (id),
  52. FOREIGN KEY (id) REFERENCES STDS_base (id) ON DELETE CASCADE
  53. );
  54. -- Create a trigger to update the modification time and revision number in case the metadata or timestanps have been updated
  55. -- Uncommented due to performance issues
  56. --CREATE TRIGGER update_STDS_abs_time AFTER UPDATE ON STDS_absolute_time
  57. -- BEGIN
  58. -- UPDATE STDS_base SET modification_time = datetime("NOW") WHERE id = old.id;
  59. -- UPDATE STDS_base SET revision = (revision + 1) WHERE id = old.id;
  60. -- END;
  61. --CREATE TRIGGER update_STDS_rel_time AFTER UPDATE ON STDS_relative_time
  62. -- BEGIN
  63. -- UPDATE STDS_base SET modification_time = datetime("NOW") WHERE id = old.id;
  64. -- UPDATE STDS_base SET revision = (revision + 1) WHERE id = old.id;
  65. -- END;
  66. --CREATE TRIGGER update_STDS_spatial_extent AFTER UPDATE ON STDS_spatial_extent
  67. -- BEGIN
  68. -- UPDATE STDS_base SET modification_time = datetime("NOW") WHERE id = old.id;
  69. -- UPDATE STDS_base SET revision = (revision + 1) WHERE id = old.id;
  70. -- END;