about heap_insert() function

Поиск
Список
Период
Сортировка
От Seung-Hyun Jeong
Тема about heap_insert() function
Дата
Msg-id 3C0E17C9.4CCAF1ED@cs.man.ac.uk
обсуждение исходный текст
Ответы Re: about heap_insert() function  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Hi,

Let me ask you some questions about heap_insert().
I'm trying to insert tuples into a existing table by using intenal
functions
bypassing the query executor.
For example, let's assume that the table name is "MyTable" having a Box
type attribute.
And I want to insert a box '((1,1),(2,2))' into the table.

The following is an internal function call sequence that I think I
should
follow.

Does it make sense?

{  Relation  relation;  Oid       oid;  HeapTuple tup;  Box       box;
  r = heap_open("MyTable", RowExclusiveLock);    box.high.x = 2;  box.high.y = 2;  box.low.x  = 1;  box.low.y  = 1;
..........................   oid = insert_heap(r, tup);  heap_close(r, NoLock)
 
}

Now, what I don't know is how to set values to HeapTuple tup.
The following data structure shows the fields that I need to fill in.  
I found some fields are set by heap_insert() function, and I marked
with "&". But I have still some fields needing to be set. Especilly,
I have no idea on what I need to set for a box, the actual data which is
going to be stored on PostgreSQL's database.

Does anybody know a good example concerning my question?typedef struct
HeapTupleHeaderData
{              Oid             t_oid;          /* & OID of this tuple -- 4
bytes */       CommandId       t_cmin;         /* & insert CID stamp -- 4 bytes
each */       CommandId       t_cmax;         /*   delete CommandId stamp */       TransactionId   t_xmin;         /* &
insertXID stamp -- 4 bytes
 
each */       TransactionId   t_xmax;         /* & delete XID stamp */       ItemPointerData t_ctid;         /*
currentTID of this or
 
newer tuple */       int16           t_natts;        /*     number of attributes */       uint16          t_infomask;
 /* & various infos */       uint8           t_hoff;         /*     sizeof() tuple header */       bits8
t_bits[MinHeapTupleBitmapSize/ 8];
 
} HeapTupleHeaderData;

typedef struct HeapTupleData
{       uint32          t_len;          /*   length of *t_data */       ItemPointerData t_self;         /*
SelfItemPointer*/       Oid             t_tableOid;     /* & table the tuple came from
 
*/       MemoryContext   t_datamcxt;     /*   memory context of
allocation */       HeapTupleHeader t_data;         /*   -> tuple header and data */
} HeapTupleData;


Cheers.


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: pg_regress.sh overrides PGPORT
Следующее
От: Manuel Sugawara
Дата:
Сообщение: Re: date formatting and tab-complete patch