Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: CHECK-Constraint mit WHERE ?



Hallo Martin,

Martin Spott wrote:
> Ich moechte aber, dass der Constraint nur auf bestimmte Geometrien
> angewendet wird und wuensche mir sinngemaess so etwas wie:
>
>   CONSTRAINT enforce_covertype CHECK (covertype >= 0 AND covertype <
>     6) WHERE geomtype LIKE 'POLYGON%'


japp das Problem kenne ich. Ich habe folgende Lösung:

CONSTRAINT name CHECK (Where-Bedingung AND Eigentliche-Prüfung) OR NOT
Where-Bedingung

also in Deinem Fall:

CONSTRAINT enforce_covertype CHECK ((geomtype LIKE 'POLYGON%') AND
(covertype >= 0 AND covertype < 6)) OR NOT (geomtype LIKE 'POLYGON%')

so in dem Muster lassen sich sehr einfach bedingte Constraints realisieren.

hth

Tobias




Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group