Adding INTERVAL to TIME in SQL
Adding INTERVAL to TIME in SQL
In PostgreSQL (Using pgAdmin 3... That is what my school demands us to use) I'm having an error message when I try and check in a trigger if the NEW event is at the same time as another event going on. 'stime' is in data type TIME and stands for "start time" and 'duration' is in data type INTERVAL.
if (NEW.stime >= schedule.stime AND NEW.stime <= (schedule.stime + schedule.duration))
--Checking if the new event happens while another event is.
The given error is as follows:
ERROR: missing FROM-clause entry for table "schedule"
LINE 5: (NEW.stime >= schedule.stime AND NEW.stime <= (schedule.st...
^
QUERY: SELECT (NEW.sdate IN (SELECT sdate FROM schedule)) AND
--Checking for events in the room at given date.
(NEW.rno IN (SELECT rno FROM schedule WHERE NEW.sdate = schedule.sdate AND NEW.bno = schedule.bno)) AND
--Checking if the new event happens while another event is.
(NEW.stime >= schedule.stime AND NEW.stime <= (schedule.stime + schedule.duration))
CONTEXT: PL/pgSQL function trigf1() line 12 at IF
********** Error **********
ERROR: missing FROM-clause entry for table "schedule"
SQL state: 42P01
Context: PL/pgSQL function trigf1() line 12 at IF
Right! I'll edit the post to include the error
– Tal Mushkin
8 hours ago
1 Answer
1
I guess schedule
is a table (maybe the table the trigger is on?) and the inserted record may not conflict with any of the records of that table.
schedule
If my guess is right you can try to change you line to:
IF EXISTS (SELECT *
FROM schedule
WHERE new.stime >= schedule.stime
AND new.stime <= (schedule.stime + schedule.duration))
If my guess is wrong or my suggestion didn't help, please post the CREATE TABLE
statement of the table the trigger is on and that of schedule
shouldn't that be the same table. IF schedule
is something else than a table, please explain what it is and also post the CREATE
statement. Post the full CREATE
statement of the trigger function and the CREATE TRIGGER
statement as well. And describe what the condition for that IF
should be.
CREATE TABLE
schedule
schedule
CREATE
CREATE
CREATE TRIGGER
IF
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
That leaves a lot open. Knowing the error message might help to help you for starters.
– sticky bit
8 hours ago