2021年3月17日星期三

Get cursor and fetch in a single statement

I need to get a cursor and fetch from it in a single SQL statement. This is because we are using MetaBase and it does not allow multiple statements.

So this:

select Adam_Cursor_Test();    fetch all in "MyCursor";  

is no good.

It needs to be something like this pseudo code:

-- Assuming 'select Adam_CursorTest()' gave the cursor name, which I know it doesn't    fetch all in (select Adam_Cursor_Test());  

I tried:

with cte1 as  (      select Adam_Cursor_Test()  )    fetch all in "MyCursor";  

which I thought was quite ingenious, but Postgres thought was a syntax error.

The name of the cursor is a side point really. It would be nice to get that dynamically too but for now I'd be delighted to get it to work at all.

Is there any way of doing this?

https://stackoverflow.com/questions/66675667/get-cursor-and-fetch-in-a-single-statement March 17, 2021 at 10:59PM

没有评论:

发表评论