Giter Site home page Giter Site logo

Panic on parameterized queries about pq HOT 5 CLOSED

lib avatar lib commented on August 21, 2024
Panic on parameterized queries

from pq.

Comments (5)

nikoudel avatar nikoudel commented on August 21, 2024

Ok, found it :) No question signs allowed.

FAILS: rows, err := db.Query("select * from customer where id = ?", 1)
WORKS: rows, err := db.Query("select * from customer where id = ($1)", 1)

from pq.

taylortrimble avatar taylortrimble commented on August 21, 2024

Would anyone care to enlighten me on why the question mark fails? ? is used in the http://golang.org/pkg/database/sql examples, and I didn't see the other syntax until here!

from pq.

msakrejda avatar msakrejda commented on August 21, 2024

We probably shouldn't panic (and/or document the parameter markers), but I don't see any standard parameter markers documented in the database/sql package--are there such? I know JDBC has them but some other DB APIs don't, and doing anything other than what Postgres natively supports (the dollar-prefixed ordinals) is rather hard to do correctly, as it involves parsing the query string in the driver.

from pq.

kisielk avatar kisielk commented on August 21, 2024

The parameter markers in database/sql are driver-specific, so yes, the query would need to be parsed and re-written by the driver. That seems error-prone.

from pq.

taylortrimble avatar taylortrimble commented on August 21, 2024

Absolutely we wouldn't translate requests! Original post was on my first day of SQL, so I just hadn't realized that parameter substitution was specific to the driver. Thanks! 💟

from pq.

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.