Giter VIP home page Giter VIP logo

Comments (24)

GrandFelix avatar GrandFelix commented on June 15, 2024 1

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.

microo8 avatar microo8 commented on June 15, 2024

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.

GrandFelix avatar GrandFelix commented on June 15, 2024

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.

GrandFelix avatar GrandFelix commented on June 15, 2024

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.

microo8 avatar microo8 commented on June 15, 2024

I'll check what I can do with looking on OID of the type. But only when I will have time.

from plgo.

remotejob avatar remotejob commented on June 15, 2024

I am as well need get 'Jsonb' type in trigger. As I understand interface{} don't work? :)

from plgo.

GrandFelix avatar GrandFelix commented on June 15, 2024

@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.

microo8 avatar microo8 commented on June 15, 2024

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.

remotejob avatar remotejob commented on June 15, 2024

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.

GrandFelix avatar GrandFelix commented on June 15, 2024

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.

microo8 avatar microo8 commented on June 15, 2024

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.

microo8 avatar microo8 commented on June 15, 2024

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.

GrandFelix avatar GrandFelix commented on June 15, 2024

Sorry for delay. Here is the output of the command that you have said to run https://pastebin.com/paw32kjR

from plgo.

remotejob avatar remotejob commented on June 15, 2024

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.

microo8 avatar microo8 commented on June 15, 2024

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.

remotejob avatar remotejob commented on June 15, 2024

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.

GrandFelix avatar GrandFelix commented on June 15, 2024

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.

GrandFelix avatar GrandFelix commented on June 15, 2024

Hi @remotejob Im still stuck here. Do you have any tip what Im doing it wrong or maybe where is the problem ?

from plgo.

microo8 avatar microo8 commented on June 15, 2024

What C compiler you have?

from plgo.

GrandFelix avatar GrandFelix commented on June 15, 2024

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.

microo8 avatar microo8 commented on June 15, 2024

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.

GrandFelix avatar GrandFelix commented on June 15, 2024

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.

microo8 avatar microo8 commented on June 15, 2024

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.

GrandFelix avatar GrandFelix commented on June 15, 2024

@microo8 thanks

from plgo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.