Questions tagged [pgx]

pgx is a pure Go driver and toolkit for PostgreSQL.

Go module github.com/jackc/pgx is a pure Go driver and toolkit for PostgreSQL.

119 questions
3
votes
0 answers

What is the difference between database/sql connection & pgx pool on golang?

I'm trying to use ent on golang backed with postgresql DB. Current legacy code uses pgxpool for connection pool. But ent does not support pgx pool, and only support standard connection pool of database/sql. What is difference between two? Is it ok…
3
votes
0 answers

Looking for example of GORM / pgx connecting to postgres with Kerberos

Been looking for an example or documentation leveraging kerberos with GORM or pgx, to connect to Postgres Db. Found some references, on pgx import ( "github.com/jackc/pgconn" "github.com/otan/gopgkrb5" ) func init() { …
3
votes
1 answer

In Go, what is the proper way to use context with pgx within http handlers?

Update 1: it seems that using a context tied to the HTTP request may lead to the 'context canceled' error. However, using the context.Background() as the parent seems to work fine. // This works, no 'context canceled' errors ctx, cancel :=…
lifebythedrop
  • 401
  • 3
  • 18
3
votes
0 answers

pgx is not returning rows after I do an insert

Im just doing an insert using the following code, and while i can see the data in the database, pgx is not returning any rows. rows, err := db.Query(context.Background(), ` INSERT INTO reservation (room_id, user_id) VALUES …
discodowney
  • 1,475
  • 6
  • 28
  • 58
3
votes
1 answer

How to determine which goroutine is blocking execution?

all. I have a small parser that writes found data to Postgres, as database framework I use https://github.com/jackc/pgx. I write parsed data to an unbuffered channel from various goroutines. I have special goroutine where I read data from this…
3
votes
1 answer

Pgxpool returns "pool closed" error on Scan

I'm trying to implement pgxpool in a new go app. I keep getting a "pool closed" error after attempting a scan into a struct. The pgx logger into gives me this after connecting. I thought the pgxpool was meant to remain…
markhorrocks
  • 1,199
  • 19
  • 82
  • 151
3
votes
2 answers

conn closed when trying to make an insert into postgresql

I try to insert a user into postgres database and get three parameters back for futher processing but always get the error 'conn closed': package db import ( "context" "os" "github.com/jackc/pgx/v4" ) const ( insertSql = "INSERT…
3
votes
2 answers

GoLang PGX Postgresql

I am looking to switch from lib/pg over to pgx but I cannot get a simple working select to work in pgx. Wondering if someone can point out what is wrong with this code. Why it is not working? No problem with lib/pg but with pgx their must be…
user10078199
  • 141
  • 2
  • 8
3
votes
0 answers

How to assign pgtype.UUIDArray to []uuid.UUID?

I use Go + Postgres. To work with Postgres I use pgx. I have an array of UUID in my Postgres table and a Struct with []*uuid.UUID (from github.com/gofrs/uuid) in Go (see code below). The problem is that I always get error when I try to use AssignTo…
Klimbo
  • 1,308
  • 3
  • 15
  • 34
2
votes
1 answer

Is there a way for sqlc to generate code that can use pgxpool

I started using recently sqlc with jackc/pgx/v5. I would like to be able to use pgxpool as well, but there is really no good way to use pgxpool after sqlc takes over in the flow. For instance, this is how I initialize the connection pool: var err…
x80486
  • 6,627
  • 5
  • 52
  • 111
2
votes
1 answer

Cannot read json range as pgtype.Int4range

I am trying to read a range as json but I am seeing an issue while I do json.unmarshal. here is a test code- import ( "encoding/json" "testing" "github.com/jackc/pgtype" "github.com/stretchr/testify/assert" ) type…
mistermims
  • 77
  • 4
2
votes
1 answer

Scanning a range type using pgx

I have column of the type int4range and would like to scan it using pgx. I am defining the type as pgtype.Int4range but I am seeing the error cannot assign &{{18 2} {86 2} i e 2} to **int64 All I am doing is for rows.Next() { .... err =…
mistermims
  • 77
  • 4
2
votes
1 answer

Need to update PSQL row of a composite type in golang with jack/pgx

I am trying to insert/update data in PostgreSQL using jackc/pgx into a table that has column of composite type. This is the table type written as a golan struct: // Added this struct as a Types in PSQL type DayPriceModel struct { Date …
Krushnal Patel
  • 422
  • 2
  • 14
2
votes
1 answer

What driver name do I use to connect Go sqlx to Postgres using the pgx driver?

Or alternatively, what additional imports do I need? I'd like to start using Postgres as my main DBMS for some development I am doing, and my research suggests that pgx is the database driver of choice at this time. I have setup a connection…
Peter
  • 5,455
  • 7
  • 46
  • 68
2
votes
1 answer

Bulk insert csv data using pgx.CopyFrom into a postgres database

I'm once again trying to push lots of csv data into a postgres database. In the past I've created a struct to hold the data and unpacked each column into the struct before bumping the lot into the database table, and that is working fine, however,…
Peter Nunn
  • 2,110
  • 3
  • 29
  • 44