pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedconstraint via selection
4+ messages / 3 participants
[nested] [flat]
* constraint via selection
@ 2001-11-17 12:18 Horst Herb <hherb@malleenet.net.au>
2001-11-17 13:00 ` Re: constraint via selection Horst Herb <hherb@malleenet.net.au>
0 siblings, 1 reply; 4+ messages in thread
From: Horst Herb @ 2001-11-17 12:18 UTC (permalink / raw)
To: pgsql-sql
Dear list,
I have two simplified tables "country" and "location":
create table country (
code char(2) primary key,
name varchar(60)
);
create table location (
id serial primary key,
country char(2) references country(code),
[...]
);
Location should have a foreign key to country.code, but for performance &
ressource reasons it would be much better to have a copy of the country
code in location.country rather than a foreign key:
create table location (
id serial primary key,
country char(2) check ...
);
What would the most efficient formulation of the "check" constraint be in
this case?
Horst
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: constraint via selection
2001-11-17 12:18 constraint via selection Horst Herb <hherb@malleenet.net.au>
@ 2001-11-17 13:00 ` Horst Herb <hherb@malleenet.net.au>
2001-11-17 19:09 ` Re: constraint via selection Aasmund Midttun Godal <postgresql@envisity.com>
2001-11-17 21:06 ` Re: constraint via selection Stephan Szabo <sszabo@megazone23.bigpanda.com>
0 siblings, 2 replies; 4+ messages in thread
From: Horst Herb @ 2001-11-17 13:00 UTC (permalink / raw)
To: pgsql-sql
> What would the most efficient formulation of the "check" constraint be
> in this case?
Sorry, I probably should reformulate my question into "is there a more
effficient constraint than a foreign key constraint for this simple
problem"?
Horst
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: constraint via selection
2001-11-17 12:18 constraint via selection Horst Herb <hherb@malleenet.net.au>
2001-11-17 13:00 ` Re: constraint via selection Horst Herb <hherb@malleenet.net.au>
@ 2001-11-17 19:09 ` Aasmund Midttun Godal <postgresql@envisity.com>
1 sibling, 0 replies; 4+ messages in thread
From: Aasmund Midttun Godal @ 2001-11-17 19:09 UTC (permalink / raw)
To: hherb@malleenet.net.au; +Cc: pgsql-sql
I don't know much about this issue. but perhaps, since I assume the country codes are static, it would be faster if you just checked each individual value (especially if there are few of them) like so
CHECK code = 'no' OR code = 'de' OR code = 'se', etc.
I don't know.
Regards,
Aasmund.
On Sun, 18 Nov 2001 00:00:57 +1100, Horst Herb <hherb@malleenet.net.au> wrote:
>
> Sorry, I probably should reformulate my question into "is there a more
> effficient constraint than a foreign key constraint for this simple
> problem"?
>
> Horst
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
Aasmund Midttun Godal
aasmund@godal.com - http://www.godal.com/
+47 40 45 20 46
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: constraint via selection
2001-11-17 12:18 constraint via selection Horst Herb <hherb@malleenet.net.au>
2001-11-17 13:00 ` Re: constraint via selection Horst Herb <hherb@malleenet.net.au>
@ 2001-11-17 21:06 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
1 sibling, 0 replies; 4+ messages in thread
From: Stephan Szabo @ 2001-11-17 21:06 UTC (permalink / raw)
To: Horst Herb <hherb@malleenet.net.au>; +Cc: pgsql-sql
On Sun, 18 Nov 2001, Horst Herb wrote:
> > What would the most efficient formulation of the "check" constraint be
> > in this case?
>
> Sorry, I probably should reformulate my question into "is there a more
> effficient constraint than a foreign key constraint for this simple
> problem"?
Hmm, it depends. You probably can't manage it through check constraints
unless you knew the values (at which point you might not even the other
table) since I'm pretty sure we don't support check constraints with
subselects in them. It's possible that for your application you could
manage to make a trigger that beats the foreign key constraint and
do it that way.
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2001-11-17 21:06 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-11-17 12:18 constraint via selection Horst Herb <hherb@malleenet.net.au>
2001-11-17 13:00 ` Horst Herb <hherb@malleenet.net.au>
2001-11-17 19:09 ` Aasmund Midttun Godal <postgresql@envisity.com>
2001-11-17 21:06 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
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