postgresql - Resetting sequential scan position for repeated SPI calls -


i'm using spi postgres cursor fetch data. looks this:

 spi_connect();  snprintf(sql, sizeof(sql), "select * %s;", datatablename);  cursorplan = spi_prepare(sql, 0, null);  cursorportal = spi_cursor_open(null, cursorplan, null, null, 1);  spi_cursor_fetch(cursorportal, direction, cursor_buffer_size); 

before fetching execute

select * coords4_1 limit 5; 

and get

         x         |         y -------------------+-------------------  -138.272695243359 | -185.774616431445  -170.132300350815 |  35.1918349042535   148.739065974951 |  213.159712031484    105.91473756358 | -375.821752008051   418.450653553009 | -69.8341866955161 

then start fetching. table big interrupt fetching reasons.

i execute

select * coords4_1 limit 5; 

again , get

231.340305414051 -443.616589065641 65.2282955124974 412.122126668692 434.384567663074  63.0593989044428 -19.7921730577946 -223.832104355097 -122.094649355859 467.992015648633 

this query returns same result in psql , in program call. necessary restart server first result again.

it seems table cursor stoped on place in table. know there no guarantees on select query result sequence. possible reinitialize table cursor without restarting server?

select * coords4_1 limit 5;

there's no order by clause here, you're telling server "give me whatever 5 results feel like".

for reasons of implementation detail, postgresql returns table contents in order. because of synchronized scans code. isn't guaranteed , code relies on utterly broken.

add order by clause, or use real cursor if want cursor-like behavior.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -