Обсуждение: calling elog possibly causing problem in DirectFunctionCall1

Поиск
Список
Период
Сортировка

calling elog possibly causing problem in DirectFunctionCall1

От
"Rajesh Kumar Mallah"
Дата:
Hi ,<br />In certain C trigger function following code snippet causes ERROR:<br
/>---------------------------------------------------<br/>elog (NOTICE , "before calling DirectFunctionCall1");<br /> 
data->time_stamp= <br />    DirectFunctionCall1(timestamptz_in, CStringGetDatum("now"));<br />elog (NOTICE , "after
callingDirectFunctionCall1");<br />----------------------------------------------------<br /><br />begin work;INSERT
INTO audittest.test_table (name,foo) values ('test','test'); rollback;<br />BEGIN<br />NOTICE:  before calling
DirectFunctionCall1<br/>ERROR:  timestamp(-1073748880) precision must be between 0 and 6<br />ROLLBACK<br /><br />If
theelog before DirectFunctionCall1 is removed the code works fine. <br /><br />begin work;INSERT INTO 
audittest.test_table(name,foo) values ('test','test'); rollback;<br />BEGIN<br />NOTICE:  after calling
DirectFunctionCall1<br/>INSERT 0 1<br />ROLLBACK<br /><br />Can anyone please explain how removing a elog makes a
difference?<br /><br />Regds<br />Mallah.<br /><br /><br /><br /><br /><br /><br /> 

Re: calling elog possibly causing problem in DirectFunctionCall1

От
Tom Lane
Дата:
"Rajesh Kumar Mallah" <mallah.rajesh@gmail.com> writes:
>   data->time_stamp =
>     DirectFunctionCall1(timestamptz_in, CStringGetDatum("now"));

This code is incorrect, as timestamptz_in takes three arguments.
        regards, tom lane


Re: calling elog possibly causing problem in DirectFunctionCall1

От
"Rajesh Kumar Mallah"
Дата:


On 12/1/06, Tom Lane <tgl@sss.pgh.pa.us> wrote:
"Rajesh Kumar Mallah" <mallah.rajesh@gmail.com> writes:
>   data->time_stamp =
>     DirectFunctionCall1(timestamptz_in, CStringGetDatum("now"));

This code is incorrect, as timestamptz_in takes three arguments.

Dear Sir,

thanks for the kind reply.

field time_stamp of data is declared as:
 Datum time_stamp;

it is supposed to be populated with current timestamp , (now())
can you please tell me what should be passed as the third argument?

Regds
Mallah.



                        regards, tom lane

Re: calling elog possibly causing problem in DirectFunctionCall1

От
"Rajesh Kumar Mallah"
Дата:


On 12/1/06, Tom Lane <tgl@sss.pgh.pa.us> wrote:
"Rajesh Kumar Mallah" <mallah.rajesh@gmail.com> writes:
>   data->time_stamp =
>     DirectFunctionCall1(timestamptz_in, CStringGetDatum("now"));

This code is incorrect, as timestamptz_in takes three arguments.

replaced it with:

data->time_stamp = DirectFunctionCall3(timestamptz_in,
                CStringGetDatum("now"),
                ObjectIdGetDatum(InvalidOid),
                Int32GetDatum(-1))

now it works fine. (code lifted from contrib/spi/moddatetime.c(line 73)
hopefully its correct.

                        regards, tom lane