From: | Gunnar Wolf <gwolf(at)gwolf(dot)cx> |
---|---|
To: | pgsql-ayuda(at)tlali(dot)iztacala(dot)unam(dot)mx |
Subject: | [Pgsql-ayuda] default a una función |
Date: | 2003-08-23 00:40:28 |
Message-ID: | 20030823004028.GV1262@gwolf.cx |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
Hola,
Me topé hoy con un problema: Tengo una tabla que relaciona a otras dos
indicando un órden específico:
| Column | Type | Modifiers
|---------------+---------+-----------
| person_id | integer | not null
| proposal_id | integer | not null
| mention_order | integer | not null
Creé la siguiente función:
|CREATE OR REPLACE FUNCTION next_author_mention_order(integer) returns
|INTEGER AS
|'DECLARE
| prop_id ALIAS FOR $1;
| verif_prop_id INTEGER;
| highest_m_o INTEGER;
|BEGIN
| -- Check that the proposal exists
| SELECT INTO verif_prop_id id FROM proposal WHERE id = prop_id;
| IF NOT FOUND THEN
| RETURN 0;
| END IF;
| SELECT INTO highest_m_o mention_order FROM authors WHERE proposal_id = prop_id ORDER BY mention_order DESC;
| IF NOT FOUND THEN
| -- No authors have been registered for this proposal yet.
| -- Next available number is 1.
| RETURN 1;
| END IF;
| return highest_m_o + 1;
|END;'
|LANGUAGE 'plpgsql';
Quisiera que el valor de salida de esta función fuera el valor default
para nuevas inserciones, de modo que pudiera hacerlas pasando sólo el
person_id y el proposal_id. Sin embargo, claro está:
|ALTER TABLE authors ALTER COLUMN mention_order SET DEFAULT next_author_mention_order(proposal_id);
|ERROR: cannot use column references in DEFAULT clause
¿Hay algún modo de lograr lo que estoy buscando?
Saludos,
--
Gunnar Wolf - gwolf(at)gwolf(dot)cx - (+52-55)5630-9700 ext. 1366
PGP key 1024D/8BB527AF 2001-10-23
Fingerprint: 0C79 D2D1 2C4E 9CE4 5973 F800 D80E F35A 8BB5 27AF
From | Date | Subject | |
---|---|---|---|
Next Message | Josué Maldonado | 2003-08-23 16:54:20 | [Pgsql-ayuda] Ultimo dia del mes |
Previous Message | sandrigo lezcano | 2003-08-22 19:25:26 | Re: [Pgsql-ayuda] Imagenes en postgresql |