Questions tagged [pq]

Pure Go Postgres driver for database/sql

Pure Go Postgres driver for database/sql

81 questions
4
votes
2 answers

Querying GORM database by its pq.StringArray attribute

I have the following gorm.Model and I want to Query my Postgres database to return Confessions that have a specific category in their .Categories attribute, but I have no idea how to Query inside a pq.StringArray. Is there a work-around? type…
Robert Jeers
  • 121
  • 1
  • 2
  • 9
3
votes
1 answer

Inserting Array of Time in Postgres via Gorm

While trying to insert into postgres db via gorm It is unable to convert time.Time information into timestamptz. The error message shown is: unable to encode time.Date(2023, time.January, 8, 1, 34, 22, 4178000, time.Local) into binary format for…
3
votes
1 answer

How to insert a hstore object using lib/pq to postgres

For this table, # \d table Table "public.table" Column | Type | Collation | Nullable | Default ------------+-----------------------------+-----------+----------+-------------------- id …
mlemboy
  • 95
  • 2
  • 6
3
votes
2 answers

Assigning the returning error to an underscore

I've been reading some Golang code from github.com/lib/pq which provides drivers for interacting with a postgres database. Among the code I came across this: go func() { select { case <-done: _ = cn.cancel() finished <-…
Rambatino
  • 4,716
  • 1
  • 33
  • 56
3
votes
1 answer

How to insert multiple rows into postgres SQL in a go

Is it possible to insert multiple rows into Postgres database at once? Could someone please suggest if there is a way to insert a slice of slices into database. I have created a slice for each row and created a another slice(multiple rows) by…
pretty08
  • 137
  • 3
  • 11
3
votes
3 answers

How to insert NUMERIC field type using lib/pq driver?

I have a table where I have a field which stores a really big number (math.big, which is bigger than uint64). I am storing it in a DECIMAL type: difficulty NUMERIC NOT NULL, So, how do I insert this field from Go code using PQ library…
Nulik
  • 6,748
  • 10
  • 60
  • 129
3
votes
1 answer

How to pass parameters to a query written in PL/pgSQL?

I wonder if it's possible to pass parameters to a query written in PL/pgSQL? I tried this, but it failed with pq: got 1 parameters but the statement requires 0 package main import ( "database/sql" "fmt" "log" _…
hgl
  • 2,034
  • 4
  • 21
  • 30
2
votes
1 answer

Postgres returns []uint8 instead of []integer

I'm saving an array of integers into PostgreSQL table, and when trying to retrieve it, I always get []uint8 instead of []int. I tried to user []integer, []bigint, []smallint. nothing works. The array represent a maximum of four items, each one…
John Doah
  • 1,839
  • 7
  • 25
  • 46
2
votes
2 answers

Recommended way of closing redundant sql.Rows object after Go routine

I'm using Go routines to send queries to PostgreSQL master and slave nodes in parallel. The first host that returns a valid result wins. Error cases are outside the scope of this question. The caller is the only one that cares about the contents of…
Tim
  • 1,585
  • 1
  • 18
  • 23
2
votes
1 answer

unique constraint violation causes entire pq.CopyIn postgresql import to fail

I'm trying to use pq.CopyIn to do bulk imports as described here: https://godoc.org/github.com/lib/pq The import is much faster than other methods I've tried but I am finding that a unique constraint violation in just one record will cause the…
JeffB
  • 31
  • 1
2
votes
2 answers

Go app using Postgres array when selecting from Redshift table

I have seen many examples online for using an array while selecting values from a table. This is the query I ran against Redshift. select * from table where colID = ANY(array[1]) This query works fine when I ran it using SQL Workbench. I am trying…
Pranavi Chandramohan
  • 1,018
  • 1
  • 7
  • 10
2
votes
1 answer

Go database/sql - Issue Commands on Reconnect

I have a small application written in Go that connects to a PostgreSQL database on another server, utilizing database/sql and lib/pq. When I start the application, it goes through and establishes that all the database tables and indexes exist. As…
Daniel
  • 518
  • 5
  • 8
2
votes
0 answers

Go 1.8 context timeout with Postgresql

In the beginning of my controller I create a context with a timeout like this: ctx, cancel := context.WithTimeout(context.Background(), time.Second * 10) defer cancel() And then I use this context in each database request like…
Rustam Ibragimov
  • 2,571
  • 7
  • 22
  • 33
1
vote
1 answer

How to add interface to non-local struct in golang?

I use https://github.com/lib/pq for getting data from postgres. For extracting data I use third-party struct, which has field with protobuf Timestamp https://pkg.go.dev/google.golang.org/protobuf/types/known/timestamppb#Timestamp So So the issue is…
abr_stackoverflow
  • 691
  • 2
  • 10
  • 26
1
vote
0 answers

How to properly scan postgresql JSON in Golang using pq driver?

I wrote a query to show data from consumer table. Table does have a payment_methods field with type JSON. When i execute update query, its working fine. But i can't find out why error occured to fetch all data. When i try to run this and this…