Обсуждение: Use SPI_exec... to insert multiples rows in C

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

Use SPI_exec... to insert multiples rows in C

От
Ian Campbell
Дата:
I need to insert up to 12 rows (bulk). Basically, new row #1's ID is the table sequence nextval and parent = null; #2 is nextval + 1 and parent = row #1's ID, etc. A hierarchy.

I figured the most performant way to do this is to have the sequence increment by the max bulk insert quantity, 12. This way I can insert all rows in one statement, which I am sure is faster that 12 insert statements (I already tried that).

Ideally, I'd like to write this in C using SPI_exec(INSERT...)  (or one of its siblings). I figured it would be most efficient to write the rows to be inserted into a tuplestore and then insert them somehow. But I don't know how to do this and cannot find any examples.

Could someone point the way for me.