pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
SQL CONSTRAINTS - Constraining time values from two attributes on a table.
4+ messages / 4 participants
[nested] [flat]

* SQL CONSTRAINTS - Constraining time values from two attributes on a table.
@ 2001-10-04 22:53  Maher, Christopher W <christopher.w.maher@intel.com>
  0 siblings, 3 replies; 4+ messages in thread

From: Maher, Christopher W @ 2001-10-04 22:53 UTC (permalink / raw)
  To: pgsql-sql

Hi,
I was looking for a solution on how to write a constraint into a ' create
table ' expression that would ensure that one ' TIME ' attribute value
called arrival_time (declared as TIME) is allways constrained to have a
value that ensures it is allways after another attribute value called
departure_time (declared as TIME). 
Any know how this constraint would be written??

Any help on this would be much appreciated,
Thanks,
Chris.



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: SQL CONSTRAINTS - Constraining time values from two attributes on	 a table.
@ 2001-10-05 20:31  Josh Berkus <josh@agliodbs.com>
  parent: Maher, Christopher W <christopher.w.maher@intel.com>
  2 siblings, 0 replies; 4+ messages in thread

From: Josh Berkus @ 2001-10-05 20:31 UTC (permalink / raw)
  To: Maher, Christopher W <christopher.w.maher@intel.com>; +Cc: pgsql-sql

Chris,

> Hi,
> I was looking for a solution on how to write a constraint into a '
> create
> table ' expression that would ensure that one ' TIME ' attribute
> value
> called arrival_time (declared as TIME) is allways constrained to have
> a
> value that ensures it is allways after another attribute value called
> departure_time (declared as TIME). 
> Any know how this constraint would be written??

Easy:

CONSTRAINT arr_dep_time CHECK ( arrival_time > departure_time )

______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco







^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: SQL CONSTRAINTS - Constraining time values from two
@ 2001-10-05 21:12  Peter Eisentraut <peter_e@gmx.net>
  parent: Maher, Christopher W <christopher.w.maher@intel.com>
  2 siblings, 0 replies; 4+ messages in thread

From: Peter Eisentraut @ 2001-10-05 21:12 UTC (permalink / raw)
  To: Maher, Christopher W <christopher.w.maher@intel.com>; +Cc: pgsql-sql

Maher, Christopher W writes:

> I was looking for a solution on how to write a constraint into a ' create
> table ' expression that would ensure that one ' TIME ' attribute value
> called arrival_time (declared as TIME) is allways constrained to have a
> value that ensures it is allways after another attribute value called
> departure_time (declared as TIME).

create table test (
    arrival_time time,
    departure_time time,
    check (arrival_time < departure_time)
);

insert into test values ('12:00', '14:30');
INSERT 20651 1

insert into test values ('12:00', '9:45');
ERROR:  ExecAppend: rejected due to CHECK constraint $1

-- 
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: SQL CONSTRAINTS - Constraining time values from two attributes on
@ 2001-10-05 23:01  Lee Harr <missive@frontiernet.net>
  parent: Maher, Christopher W <christopher.w.maher@intel.com>
  2 siblings, 0 replies; 4+ messages in thread

From: missive@frontiernet.net @ 2001-10-05 23:01 UTC (permalink / raw)
  To: pgsql-sql

> I was looking for a solution on how to write a constraint into a ' create
> table ' expression that would ensure that one ' TIME ' attribute value
> called arrival_time (declared as TIME) is allways constrained to have a
> value that ensures it is allways after another attribute value called
> departure_time (declared as TIME). 
> Any know how this constraint would be written??
> 

CREATE TABLE tablename (
 arrival_time		timestamp,
 departure_time		timestamp
  CHECK (arrival_time < departure_time)
);




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2001-10-05 23:01 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-10-04 22:53 SQL CONSTRAINTS - Constraining time values from two attributes on a table. Maher, Christopher W <christopher.w.maher@intel.com>
2001-10-05 20:31 ` Re: SQL CONSTRAINTS - Constraining time values from two attributes on	 a table. Josh Berkus <josh@agliodbs.com>
2001-10-05 21:12 ` Re: SQL CONSTRAINTS - Constraining time values from two Peter Eisentraut <peter_e@gmx.net>
2001-10-05 23:01 ` Re: SQL CONSTRAINTS - Constraining time values from two attributes on Lee Harr <missive@frontiernet.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox