50132

Why aren't my SQL placeholders being replaced (using Go pq)?

<h3>Question</h3>

As per the docs, I'm doing this

var thingname string = "asdf"; var id int err = database.QueryRow("SELECT id from things where thing = ?", thingname).Scan(&id)

but Postgres is saying

ERROR: syntax error at end of input at character 41 STATEMENT: SELECT id from things where thing = ?

I can't see that I'm doing much different to the demo code. I'm using pq.


<h3>Answer1:</h3>

The exact syntax is database dependent.

Use

err = database.QueryRow("SELECT id from things where thing = $1", thingname).Scan(&id)
<h3>Answer2:</h3>

Try this using $1 instead of ?:-

err = database.QueryRow("SELECT id from things where thing = $1", thingname).Scan(&id)

来源:https://stackoverflow.com/questions/18577855/why-arent-my-sql-placeholders-being-replaced-using-go-pq

Recommend

  • Why aren't my SQL placeholders being replaced (using Go pq)?
  • Why aren't my SQL placeholders being replaced (using Go pq)?
  • How can I change default tenant in Microsoft Graph Explorer
  • Javascript array for AJAX POST send
  • How to get .mpd file for a youtube video
  • No perfect way to detect device orientation on iPad?
  • IE6 postback in asp.net
  • What's wrong with my PNG IDAT chunk?
  • Angular: how to make NgControl react to valueChanges only of the host
  • JQuery and PHP validation problem?
  • Hive Metastore is not creating MYSQL or Derby Connection
  • Printing a flowdocument with dynamic data in WPF
  • Speed up Date#parse & Date#strptime in Ruby, more elegant way or best practice?
  • GraphiQL Returning null Values When Fetching All Records
  • IIS - ASP.NET MVC redirection
  • Scrapy + Selenium + Datepicker
  • AppEngine Paypal integration giving SSLCertificateError on localhost, using Python
  • Highlight special word in a TextBox
  • GLConsumer is already attached to a context for new SurfaceTexture
  • remove date from DateTimePicker for Compact Framework
  • jQuery YQL SELECT FROM rss variable
  • iOS App crash issue `[UIWindow warpPoint:]`
  • if you have a DLL creating a bitmap in memory, how to return it to the browser?
  • Why am I getting an Argument exception when creating event handler dynamically?
  • .Net core Hosted Services guaranteed to complete
  • opencv deskewing a contour
  • How to define a custom accuracy in Keras to ignore samples with a particular gold label?
  • Regex not working in java 1.5
  • Year over Year Stats from a Crossfilter Dataset
  • Ruby regex for matching simpliest Ruby's regexes
  • Why is ordered choice in pyparsing failing for my use case?
  • How do I add a mouse over tooltip to an Image using .DrawImage()
  • Using redis as an LRU cache for postgres
  • Google App Engine Datastore: Dealing with eventual consistency
  • Bad automatic Triangulation with Mayavi for coloring a surface known only by its corner
  • ssh remote server login script
  • How to call different template for different category archive page in woocommerce
  • Jersey serializes character value to ASCII equivalent numeric string