Questions tagged [pq]

Pure Go Postgres driver for database/sql

Pure Go Postgres driver for database/sql

81 questions
0
votes
1 answer

Using primary keys in postgrSQL

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…
Nathan Takemori
  • 139
  • 1
  • 10
0
votes
1 answer

pq QueryRow Scan fails with invalid memory address or nil pointer dereference

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…
Mike Hawkins
  • 2,144
  • 5
  • 24
  • 42
0
votes
1 answer

Memory leaks when using db connections within a for loop

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…
Kingindanord
  • 1,754
  • 2
  • 19
  • 48
0
votes
1 answer

pq.NewListener/Listen blocks with pq: syntax error at or near "listen"

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" …
cpuNram
  • 205
  • 2
  • 12
0
votes
1 answer

err cannot be infered from db.QueryRow()

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" …
anta40
  • 6,511
  • 7
  • 46
  • 73
0
votes
1 answer

Invalid byte sequence allthough string is a valid UTF8

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…
In0cenT
  • 481
  • 2
  • 11
  • 25
0
votes
1 answer

replace a x with headertext

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 …
0
votes
2 answers

Go Mock postgresql errors

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") …
Arun
  • 1,933
  • 2
  • 28
  • 46
0
votes
0 answers

Passing array of array in a IN condition placeholder with go sql

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…
B. Delor
  • 51
  • 6
0
votes
1 answer

Infinite loop when db.Ping() is called

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…
DJBrunelle
  • 25
  • 7
0
votes
0 answers

Insert in postgres jsonb array causes the json escaping key and value - golang pq

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…
Walker
  • 891
  • 2
  • 11
  • 26
0
votes
1 answer

MD5 Hashed passwords: where does it get hashed?

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…
myartsev
  • 1,207
  • 2
  • 13
  • 23
0
votes
1 answer

Does Go-Gorm support insert with auto incremented ID for partitioned tables in PostgreSQL?

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…
Saurav Haloi
  • 343
  • 1
  • 2
  • 11
0
votes
2 answers

Error when add a query parameter to postgres query

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,…
Nirgn
  • 1,879
  • 4
  • 23
  • 28
0
votes
1 answer

Delete the record using libpq PQexecParams() query

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…