pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
C trigger problem : conversion of CString to Datum
3+ messages / 2 participants
[nested] [flat]

* C trigger problem : conversion of CString to Datum
@ 2010-02-20 15:05  Guy Deleeuw <G.De_Leeuw@eurofer.be>
  0 siblings, 1 reply; 3+ messages in thread

From: Guy Deleeuw @ 2010-02-20 15:05 UTC (permalink / raw)
  To: pgsql-admin

Hello,

I cannot convert properly a cstring to a Datum :
Here my code :
   int                   attColNumber;
   Datum                 new_barcode;
   bool                  isnull        = 0;
   char                  barcode[14];

    elog(INFO, "gd_trigfunc_before_article_insert() : bar_code = %s", 
barcode);
    attColNumber = COL_BARCODE;
    new_barcode = CStringGetDatum(barcode);
     workTuple = SPI_modifytuple(trigdata->tg_relation, 
trigdata->tg_trigtuple, 1, &attColNumber, &new_barcode, &isnull);

the result :

# INSERT INTO t_articles VALUES (4001, 1, '065', 'White', NULL, 'XS', null);
INFO:  gd_trigfunc_before_article_insert() : bar_code = 5492850000012
INSERT 0 1
# select * from t_articles WHERE k_id > 2000;
  k_id | product_id | color_id | color_desc | height | size |   bar_code
------+------------+----------+------------+--------+------+--------------
  4001 |          1 | 065      | White      |        | XS   | 492850000012
(1 ligne)

Missing the firs digit of the barcode.

Thanks in advance for your help
Regards
Guy



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: C trigger problem : conversion of CString to Datum
@ 2010-02-20 15:45  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Guy Deleeuw <G.De_Leeuw@eurofer.be>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2010-02-20 15:45 UTC (permalink / raw)
  To: Guy Deleeuw <G.De_Leeuw@eurofer.be>; +Cc: pgsql-admin

Guy Deleeuw <G.De_Leeuw@eurofer.be> writes:
> I cannot convert properly a cstring to a Datum :

Well, CStringGetDatum would be the proper thing to use if you meant to
produce a Datum of type "cstring".  But what you need here is a Datum
of the same type as the target column, which evidently isn't cstring.
Most likely you need to convert the string to type text.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: C trigger problem : conversion of CString to Datum
@ 2010-02-21 10:15  Guy Deleeuw <G.De_Leeuw@eurofer.be>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Guy Deleeuw @ 2010-02-21 10:15 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-admin

Hi Tom

Many thanks for your answer, all work fine now :-)

Regards
Guy

Le 20/02/10 16:45, Tom Lane a écrit :
> Guy Deleeuw<G.De_Leeuw@eurofer.be>  writes:
>    
>> I cannot convert properly a cstring to a Datum :
>>      
> Well, CStringGetDatum would be the proper thing to use if you meant to
> produce a Datum of type "cstring".  But what you need here is a Datum
> of the same type as the target column, which evidently isn't cstring.
> Most likely you need to convert the string to type text.
>
> 			regards, tom lane
>    



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2010-02-21 10:15 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-02-20 15:05 C trigger problem : conversion of CString to Datum Guy Deleeuw <G.De_Leeuw@eurofer.be>
2010-02-20 15:45 ` Tom Lane <tgl@sss.pgh.pa.us>
2010-02-21 10:15   ` Guy Deleeuw <G.De_Leeuw@eurofer.be>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox