Giter Site home page Giter Site logo

Comments (6)

marcboeker avatar marcboeker commented on July 24, 2024

Thanks for reporting this. Do you have some sample code that I can use to probably add the missing data type. That would be great. Thanks!

from go-duckdb.

bruth avatar bruth commented on July 24, 2024

Thanks for the response and sorry for the delay! I actually hope to have a PR opened up next week some time.

from go-duckdb.

marcboeker avatar marcboeker commented on July 24, 2024

No worries, I've already started with a PR. But the serialisation of the Map{"foo": "bar", "bam": "baz"} to the SQL representation map(['foo', 'bam'], ['bar', 'baz']) is not that trivial, as a map could contain another map as its key or value. For numericals and strings my implementation already works.

from go-duckdb.

marcboeker avatar marcboeker commented on July 24, 2024

After I have racked my brain about serializing a map to a query parameter, I have checked the DuckDB APIs for prepared statements and have found no way to bind a map to a parameter. After thinking twice about it, I'm unsure what your use case is.
Could you please show me the query you want to use. This would help me to understand the problem better. Thanks!

from go-duckdb.

andyyu2004 avatar andyyu2004 commented on July 24, 2024

Hey @marcboeker, I have a motivating example for the same issue except with a slice.

This fails with the error sql: converting argument $1 type: unsupported type []string, a slice of string.

func TestSliceParameter(t *testing.T) {
	db := openDB(t)
	defer db.Close()

	_, err := db.Exec("CREATE TABLE foo (x text)")
	require.NoError(t, err)

	_, err = db.Exec("INSERT INTO foo VALUES ('test')")
	require.NoError(t, err)

	_, err = db.Query("SELECT x FROM foo WHERE x = ANY($1)", []string{"test"})
	require.NoError(t, err)
}

from go-duckdb.

marcboeker avatar marcboeker commented on July 24, 2024

Hi @andyyu2004, thanks for the example. As we're internally using the DuckDB parameter bind API, there is currently no function for binding slices.

A dirty hack would be to interpolate the placeholder with multiple placeholders an then iterating over the slice and binding each item separately. But I would highly suggest to avoid this, as it can get ugly quickly.

For these kind of use-cases I have used sqlx in the past. See the example under the "IN queries" section on this page. Maybe you could try this?

from go-duckdb.

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.