Re: actualizar columna fecha
- From: "Jaime Casanova" <systemguards(at)gmail(dot)com>
- To: "José Fermín Francisco Ferreras" <josefermin54(at)hotmail(dot)com>
- Cc: "foro postgresql" <pgsql-es-ayuda(at)postgresql(dot)org>
- Subject: Re: actualizar columna fecha
- Date: Thu, 24 Jan 2008 21:27:34 -0500
- Message-id: <c2d9e70e0801241827i75d192a8ueb212397ef94d88a(at)mail(dot)gmail(dot)com>
2008/1/24 José Fermín Francisco Ferreras <josefermin54(at)hotmail(dot)com>:
> hola, tengo la siguiente tabla de prueba
>
> create table prueba
> (
> codigo integer primary key,
> fecha date default now()
> );
>
> hago el correspondiente insert a la tabla /* las inserciones fueron en
> fecha 2008-01-23 */
>
> insert into prueba(codigo)
> values
> (1),(2),(3);
>
> entonces modifico el codigo d una d las columnas /* la actualización fue en
> fecha 2008-01-24 */
>
> update prueba
> set codigo = 4
> where codigo = 2;
>
> Bien todo va perfecto, con excepción d q me gustaría q ademas d generar la
> fecha cuando se hace un insert, me gustaría q la generara a la fecha d hacer
> un update osea q modifique la fecha.
>
con un trigger.
CREATE OR REPLACE FUNCTION upd_prueba RETURNS TRIGGER AS $$
begin
NEW.fecha := current_date;
end;
$$ LANGUAGE plpgsql;
CREATE TRIGGER trg_upd_prueba BEFORE UPDATE ON prueba
FOR EACH ROW EXECUTE PROCEDURE upd_prueba();
--
Atentamente,
Jaime Casanova
"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs and the universe trying
to produce bigger and better idiots.
So far, the universe is winning."
Richard Cook
Home |
Main Index |
Thread Index