Re: [GENERAL] Read values from Trigger out - Mailing list pgsql-general

From Karel Zak - Zakkr
Subject Re: [GENERAL] Read values from Trigger out
Date
Msg-id Pine.LNX.3.96.1000210102741.21359A-100000@ara.zf.jcu.cz
Whole thread Raw
In response to Read values from Trigger out  (Thomas Egge <teg@ratio.de>)
List pgsql-general


On Wed, 9 Feb 2000, Thomas Egge wrote:

> I have created a trigger function.
>
> could somebody tell me how I get the values from the insert in the trigger
> function.
> I tried the function
>
> SPI_getvalue(trigger,tupdesc,attnum)
>


Example:

        TupleDesc       tupdesc;
        HeapTuple       rettuple        = NULL;
    char        *value;

        if (!CurrentTriggerData)
                elog(ERROR, "triggers are not initialized");

        if (TRIGGER_FIRED_BY_UPDATE(CurrentTriggerData->tg_event))
                rettuple = CurrentTriggerData->tg_newtuple;
        else if (TRIGGER_FIRED_BY_INSERT(CurrentTriggerData->tg_event))
                rettuple = CurrentTriggerData->tg_trigtuple;
        else if (TRIGGER_FIRED_BY_DELETE(CurrentTriggerData->tg_event))
                rettuple = CurrentTriggerData->tg_trigtuple;


        tupdesc = CurrentTriggerData->tg_relation->rd_att;

        if (SPI_connect() < 0)
                elog(ERROR, "SPI_connect()");

    value = SPI_getvalue(rettuple, tupdesc, SPI_fnumber(tupdesc, "column_name"));


 ...see the PostgreSQL programmer's guide for more...

                        Karel


pgsql-general by date:

Previous
From: Daniel Forsyth
Date:
Subject: Quick Varchar Question
Next
From: "Ross J. Reedstrom"
Date:
Subject: Re: [GENERAL] view columm size.....