From: | hypatia(at)mail(dot)internet(dot)com(dot)mx |
---|---|
To: | pgsql-ayuda(at)tlali(dot)iztacala(dot)unam(dot)mx |
Subject: | Re: [pgsql-ayuda] Obligar a cierta condicion desde el SQL |
Date: | 2000-04-07 16:20:19 |
Message-ID: | 38EE0AC3.CB44E00E@mail.internet.com.mx |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
> CREATE TABLE "casilla" (
> "id_casilla" serial,
> "num_casilla" int2,
> "id_elec" int2,
> "ubicacion" text(150)
> );
>
> CREATE TABLE "formula" (
> "id_formula" serial,
> "nombre_formula" text(80),
> "id_elec" int2
> );
>
> Estas tablas estan relacionadas por una tercera:
>
> CREATE TABLE "votos" (
> "id_casilla" int2,
> "id_formula" int2,
> "num_votos" int2
> );
>
Una idea puede ser:
CREATE TABLE "votos" (
id_casilla int2,
id_formula int2,
num_votos int2,
CONSTRAINT cont1 CHECK ( match_elec(id_casilla, id_formula) ) INITIALLY
IMMEDIATE
);
CREATE FUNCTION "match_elec" (int2,int2) RETURNS bool AS
'SELECT TRUE WHERE ( SELECT id_elec FROM casilla WHERE id_casilla = $1 )
IN
( SELECT id_elec FROM formula WHERE id_formula = $2 )'
LANGUAJE 'SQL';
Pero no estoy seguro que funcione este IN.
Podria funcionar:
CREATE TABLE "votos" (
id_casilla int2,
id_formula int2,
num_votos int2,
CONSTRAINT cont1 CHECK ( casilla_elec(id_casilla) =
formula_elec(id_formula) ) INITIALLY IMMEDIATE
);
CREATE FUNCTION "casilla_elec" (int2) RETURNS int2 AS
'SELECT id_elec FROM casilla WHERE id_casilla = $1 '
LANGUAJE 'SQL';
CREATE FUNCTION "formula_elec" (int2) RETURNS int2 AS
'SELECT id_elec FROM formula WHERE id_casilla = $1'
LANGUAJE 'SQL';
Quiza si lo pruebas y checas las siguientes referencias, puedas
encontrar la mejor opci� para lo que necesitas:
file:/usr/doc/postgresql-6.5.2/postgres/sql-createtable.htm
file:/usr/doc/postgresql-6.5.2/postgres/sql-createfunction.htm
file:/usr/doc/postgresql-6.5.2/postgres/sql-select.htm
--
Saludos
Juan Pablo Rosas
--------- Pie de mensaje -------------------------------------------
Archivo historico: http://tlali.iztacala.unam.mx/maillist/pgsql-ayuda
Cancelar inscripcion:
mail to: majordomo(at)tlali(dot)iztacala(dot)unam(dot)mx
text : unsubscribe pgsql-ayuda
From | Date | Subject | |
---|---|---|---|
Next Message | José Antonio Galicia | 2000-04-07 18:09:26 | Re: [pgsql-ayuda] Obligar a cierta condicion desde el SQL |
Previous Message | Gunnar Wolf | 2000-04-07 15:02:05 | [pgsql-ayuda] Obligar a cierta condicion desde el SQL |