about heap_insert() function

From: Seung-Hyun Jeong <jeongs(at)cs(dot)man(dot)ac(dot)uk>
To: pgsql-hackers(at)postgresql(dot)org
Subject: about heap_insert() function
Date: 2001-12-05 12:49:13
Message-ID: 3C0E17C9.4CCAF1ED@cs.man.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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; /* & insert XID stamp -- 4 bytes
each */
TransactionId t_xmax; /* & delete XID stamp */
ItemPointerData t_ctid; /* current TID 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.

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message tinar 2001-12-05 13:12:07 how to chane the type
Previous Message Tom Lane 2001-12-05 11:32:45 Re: pg_regress.sh overrides PGPORT