Comments (24)
thank you @microo8. Meantime I will also try to implement it on my own. If I can solve it I will make pr.
from plgo.
that's a tough question, I'll check how it is done in pq.
meanwhile, can you test if you can Marshall
the json and input it as a string? And then convert it to jsonb in the query?
insert into table (json_col) values ($1::text::jsonb)
from plgo.
Hmmm @microo8 maybe this can help you https://github.com/plv8/plv8/blob/95ac8f77a8c13c0119eefc4b4d6f3b11d23acf25/plv8_type.cc#L303 Plv8 also have jsonb supported. I would love to help you out with this but I have just started with go and I think I cant cope with it yet :/
Ok, I will try that with text and jsonb conversion.
from plgo.
I think this with converting to text and vice versa should go but we don't want to converting it for input and output so we are looking for better option.
from plgo.
I'll check what I can do with looking on OID of the type. But only when I will have time.
from plgo.
I am as well need get 'Jsonb' type in trigger. As I understand interface{} don't work? :)
from plgo.
@remotejob yes, if you use interface{} as input type you get error that it is not supported type. Because of that we must add support for jsonb.
from plgo.
You can now use json and jsonb in query results
type ExampleJson struct {
Var1 string `json:"var1"`
Var2 int `json:"var2"`
}
stmt, _ := db.Prepare("select jsonbcol from table", nil)
row, _ := stmt.QueryRow()
var ej ExampleJson
row.Scan(&ej)
and also in queries
stmt, _ := db.Prepare("insert into table (jsonbcol) values ($1)", []string{"jsonb"})
stmt.Exec(ej)
try it out and when it works you can close the issue
from plgo.
In my case (trigger) variant:
func CrimeTrg(td *plgo.TriggerData) *plgo.TriggerRow {
var id string
var source map[string]interface{}
td.NewRow.Scan(&id,&source)
log.Println("id2",id,"source",source)
return td.NewRow
}
work for me, probably it was necessary test it before instead of try put jsonb into interface{} ?! :)
Greate!!!!
from plgo.
Ok, thats funny. Now Im getting error when building it :/ I think that something updated on my vagrant machine :/ Im getting:
# command-line-arguments /usr/bin/ld: -r and -shared may not be used together collect2: error: ld returned 1 exit status Cannot build package: exit status 2
Any tip?
from plgo.
It's similar to the #1 issue. Try to update your plgo binary
$ cd $GOPATH/src/github.com/microo8/plgo/plgo
$ git pull
$ go install
When you run plgo
it creates the package source in /tmp/plgo<somenumber>
folder.
You can go there and compile it CGO_LDFLAGS_ALLOW='.*' go build -v -x -buildmode=c-shared
. Can you then post the full output?
Meantime I try to find why is cgo adding -r
to ld
command
from plgo.
Also in the /tmp/plgo<somenumber>
try to edit the CFLAGS
and add to it -fPIC
. Something like:
#cgo CFLAGS: -I/usr/include/postgresql/server -fPIC
from plgo.
Sorry for delay. Here is the output of the command that you have said to run https://pastebin.com/paw32kjR
from plgo.
How change cgo CFLAGS: without install other Postgresql version?
I tryed
export CGO_CFLAGS=-I../postgresql-9.6.2/src/include
Don't help in
/tmp/plgo<somenumber>
pl.go:#cgo CFLAGS: -I/usr/include/postgresql/9.5/server
As I understand necessary change
pg_config
from plgo.
Try editing the pl.go
file in /tmp/plgo<somenumber>
to look like:
#cgo CFLAGS: -I/usr/include/postgresql/9.5/server -fPIC
the -I
path must be the output of pg_config --includedir-server
I cannot help you with this. Maybe if I try to make a docker container with your version of postgres, go and gcc?
from plgo.
Now
No package main in . Usage: plgo [path/to/package]
maybe add other optional parameter for example --include
I mean will be something like:
plgo --include /usr/local/pgsql/include/server plmodule/ext
from plgo.
Hi. I have tried now to pull everything again and set everything as you said but I get same error about using -r and -shared flags?
https://gist.github.com/GrandFelix/b3514feaa1e33856a519702b29582745
from plgo.
Hi @remotejob Im still stuck here. Do you have any tip what Im doing it wrong or maybe where is the problem ?
from plgo.
What C compiler you have?
from plgo.
Is this ok?
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
from plgo.
I don't know, was just thinking about the output from gcc --version
Mine is: gcc (GCC) 8.1.0
. Can you try it on a newer compiler?
from plgo.
Hi @microo8 now I have finally got time and have installed everything :) I did have to build gcc from scratch to version 8.1.0 as you have suggested it. Now I have one more question. I want to return from my function result as SETOF ? Is this possible?
from plgo.
SETOF isn't yet supported. But I can look at it. Will close this issue, because its title is completely something else, what we are discussing.
from plgo.
@microo8 thanks
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.