Comments (5)
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.
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.
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.
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.
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)
- Tx.Rollback returns ErrBadConn after context is cancelled
- Connection string parsing fails randomly HOT 2
- 1 Listener for 2 channel HOT 1
- SonarCloud Vulnerability: Make sure this PostgreSQL database password gets changed and removed from the code.
- Usage of COPY TO STDOUT WITH CSV
- RFC 9266: Channel Bindings for TLS 1.3 support
- Query extra_float_digits problem
- Is Postgres15.4 is compatible with the lib/pq package?
- What kind of mistake is this?
- how to deal with "cached plan must not change result type" error?
- Looking for a security contact to disclose a vulnerability HOT 1
- Exectuing pq.CopyIn fails with one of two errors depending on usage
- Why do I have errors in local language?
- pq: invalid array literal.
- pq: invalid input syntax for type integer HOT 2
- Private keys cause Trivy HIGH vulnerability alerts HOT 4
- Nil byte array doesn't get saved as JSONB field
- nil byte array `[]byte(nil)` is encoded as empty byte array `[]byte([])` instead of nil
- Extra DNS name verification is made in `verify-ca` mode, making it effectively `verify-full` HOT 1
- Got error pq: syntax error at the end of ... when doing custom dialer
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 pq.