0

I try to create a simple insert statement and get the error:

pq: syntax error at or near ","

txn, err := db.Begin()
stmt, err := db.Prepare(`INSERT INTO advertiser_per_day (id,advertiser_name,additional,customer_id,site_id,tracking,counter,day,month,year) VALUES (?,?,?,?,?,?,?,?,?,?)`)

If I put the statement into a query tool for postgres all works fine... Any ideas?

1 Answer 1

3

You should use ($n) instead of ? for the bound parameters.

Sign up to request clarification or add additional context in comments.

4 Comments

? is for mysql, $n works fine in my code. Are you sure parameters isn't empty ? Show the full code please.
thanks for you help. Not even getting to the place he fills the parameters.. it fails before...
i try to do this in the end: INSERT INTO advertiser_per_day (id, advertiser_name, additional, customer_id, site_id, tracking, counter, day, month, year) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) ON CONFLICT (id) DO UPDATE SET counter=counter+1 but now getting error pq: column reference "counter" is ambiguous Do you have a last guess for me. Would be awesome
Looks like postgres dont recognize what column in wich table to use. you should denoted it like advertiser_per_day.counter or something like this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.