I currently have a table:
userID | color | quantity
-------------------------
where userID is the primary key. My problem is when I try to insert to the DB (that already has one item from the same ID) I get the error: pq: duplicate key value…
I have the following function which is supposed to retrieve a single row from my ideas table:
func (s *IdeaService) GetIdea(id int64) (*ideaservice.Idea, error) {
stmt, err := s.DB.Prepare("SELECT id, name, description, created_on, last_updated…
I am trying to continuously query Postgres Database within an infinite for loop. However, it seems that the queries are not closing, the garbage collector not working probably and I face memory allocation problems.
The script design is as…
I have minio/s3 object store with lambda notifications into cockroachdb (postgres db). I am trying to monitor these events with below golang code.
package main
import (
"database/sql"
"encoding/json"
"fmt"
"github.com/lib/pq"
…
I'm trying to implement a simple POST API to insert data on Postgres DB, like this:
http://123.123.10.10/checkin?userid=clive&token=1234jhhasdbn
package main
import (
"database/sql"
"encoding/json"
"fmt"
"log"
"net/http"
…
I'm trying to write a txt to postgres bulk importer. The code currently crashes as the string which should get inserted to postgres isn't a valid UTF8: pq: invalid byte sequence for encoding UTF8: 0x00
In my code I'm checking if the strings are a…
I want to achieve the following in Power Query: in each cell, replace an x with the text of the header:
Column1 Column2 Column3 Column4 Column5
y z
x y x x
x …
As discussed in this answer, I have written code for checking a unique key violation:
if err, ok := err.(*pq.Error); ok {
if err.Code.Name() == "unique_violation" {
fail(w, http.StatusBadRequest, 0, "Item already exists")
…
Introduction
I am encountering a problem when I attempt to pass several couple of values in a IN condition. When I attempt the query in the postgres console it works fine but it fails when executed in go.
The situation
The query I'm attempting to…
I am attempting to create a basic connection to a database. The problem happens when I try to test the connection with db.Ping(); everything works until I get to this line. The Ping sends the program into an infinite loop (the function call never…
I am marshalling the data as
b, err := json.MarshalJSON(&u3)
if err != nil {
log.Println("error:", err)
}
and then insert
INSERT INTO user_list (userid, listtype, data) VALUES ($1, $2, (array[$3::json]))
The data is written as…
I am connecting to a local PostgreSQL database with an md5 hashed password.
It works but I want to understand what is happening under the hood.
Does pq hash the password before it is sent over the network? How would it know whether to hash it or…
I have a table in PostgreSQL represented as the following Go struct:
type AppLog struct {
ID int // set to auto increment in DB, also a primary key
event string
createTime time.Time
}
I configured monthly table partitioning with the…
When I write the code:
err := database.QueryRow("SELECT page_title,page_content,page_date FROM pages WHERE id=1").
Scan(&thisPage.Title, &thisPage.Content, &thisPage.Date)
Everything works fine. But I want it to not just get the page with id=1,…
I am trying to delete a record using libpq PQexecParams() function. The query is successfully returned but required row is not deleted from the table. Here is the snippet from my code for reference. I have used PQexecParams() for select and insert…