Comments (3)
I don't have the necessity for SETOF for the moment in my project but I was searching informations about the subject I found this and this
from plgo.
Is here something new maybe?
from plgo.
So the SETOF functionality isn't just eg. a function that returns an array
You cannot write something like:
func FibonacciSETOF(n int) []int {
f := make([]int, n+1, n+2)
if n < 2 {
f = f[0:2]
}
f[0] = 0
f[1] = 1
for i := 2; i <= n; i++ {
f[i] = f[i-1] + f[i-2]
}
return f
}
and expect it to be a SETOF returning function.
These functions are written so, that it is called multiple times and every time it receives the user "context" and information of where it is in the "SET" .
https://www.postgresql.org/docs/current/xfunc-c.html#XFUNC-C-RETURN-SET
It is possible to split the function to these calls. something like:
//returning the data to be stored in context and the maximum number of calls
func FibonacciSETOFInit(n int) (interface{}, int) {
f := make([]int, n+1, n+2)
if n < 2 {
f = f[0:2]
}
f[0] = 0
f[1] = 1
return f, n
}
//this function will be called n-times
//getting the context, with the data and iteration number
func FibonacciSETOFNext(ctx plgo.Context) int {
f := ctx.Value().([]int)
f[ctx.Iteration()] = f[ctx.Iteration()-1] + f[ctx.Iteration()-2]
return f[ctx.Iteration()]
}
so if you call select fibonacci(10)
plgo will generate the function where the first time it will call FibonacciSETOFInit
and then 10 times FibonacciSETOFNext
.
There is a user_fctx
pointer, to user defined data, that are allocated in the "init" phase and then used in the function calls. The problem is, that memory controlled by go, cannot be passed to C. So this context cannot be used by plgo.
And if it is somehow possible, writing something like this is complicated.
So maybe it is better to just write a function returning an array and then call it with unnest: select unnest(Fibonacci(10))
Any ideas what to do?
from plgo.
Related Issues (20)
- Postgres.h error
- Function "Sub" has not suported return type HOT 3
- Custom aggregate support HOT 3
- Support request for multiple return types aka when len(results.List) > 1 HOT 2
- What version of postgres is supported? HOT 2
- invalid operation HOT 1
- pgsql-11: error: conflicting types for 'varsize_any' HOT 2
- There is no rule for building the target “main.bc” required for “all”. Stop
- undefined symbol: getmissingattr HOT 5
- Text fields are not processed correctly. HOT 2
- How to catch and display an exception in the process of work extension ? HOT 2
- INSERT cannot be used in non-volatile function HOT 2
- invalid operation HOT 5
- There is no rule for building the target “sample.bc” required for “all”. Stop HOT 12
- Returning []byte results in server (postgres) crashes and generates incorrect SQL HOT 1
- Build error on Linux HOT 1
- psql server 11 HOT 1
- Could not determine kind of name for C.FunctionCallInfoBaseData HOT 3
- Cannot build package: exit status 2 HOT 6
- PG13 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plgo.