2024-07-31T00:40:35.sql (619B)
1 CREATE TABLE spaceplanner.floorplans ( 2 id bigserial PRIMARY KEY, 3 owner varchar REFERENCES users(name), 4 name varchar, 5 address varchar, 6 synopsis varchar, 7 updated timestamp DEFAULT now(), 8 created timestamp DEFAULT now(), 9 CONSTRAINT id UNIQUE (owner, name) 10 ); 11 12 CREATE TABLE spaceplanner.floorplan_points ( 13 floorplan int REFERENCES spaceplanner.floorplans(id), 14 id int, 15 x int, 16 y int, 17 PRIMARY KEY (floorplan, id) 18 ); 19 20 CREATE FUNCTION spaceplanner.floorplan_id (varchar, varchar) 21 RETURNS bigint 22 LANGUAGE sql 23 STABLE 24 RETURNS NULL ON NULL INPUT 25 RETURN (SELECT id FROM floorplans WHERE owner = $1 AND name = $2) ;