Code Monkey home page Code Monkey logo

Comments (6)

vmihailenco avatar vmihailenco commented on June 24, 2024

With pg.v4 you can try something like:

ints := []int{1, 2, 3}
db.Exec(`SELECT * FROM insert_batch(?)`, types.Array(ints))

But array of time types.Array([]time.Time{...}) is not supported...

from pg.

vmihailenco avatar vmihailenco commented on June 24, 2024

Overall array support is very limited right now - https://github.com/go-pg/pg/blob/v4/types/array.go#L16-L28

from pg.

drt24 avatar drt24 commented on June 24, 2024

Actually the example needs curly brackets rather than round brackets:

ints := []int{1, 2, 3}
db.Exec("SELECT * FROM insert_batch(?)", types.Array{ints})

Otherwise you get:

cannot convert ints (type []int) to type types.Array

from pg.

vmihailenco avatar vmihailenco commented on June 24, 2024

Eventually I will make it work correctly, but first I want to stabilize v4 branch and release ORM to public...

from pg.

vmihailenco avatar vmihailenco commented on June 24, 2024

FYI #138 added support for []time.Time array, but API changed slightly:

ints := []int{1, 2, 3}
times := []time.TIme{time.Now()}
db.Exec(`SELECT * FROM insert_batch(?, ?)`, pg.Array(&ints), pg.Array(&times))

There is still some work to be done, but it should be usable.

from pg.

vmihailenco avatar vmihailenco commented on June 24, 2024

I consider array support finished. See https://godoc.org/gopkg.in/pg.v4#example-DB-Model-PostgresqlArrayStructTag and https://godoc.org/gopkg.in/pg.v4#example-Array for examples.

from pg.

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.