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
18
votes
4 answers

How to scan a QueryRow into a struct with pgx

We are using a user struct with alot of fields as follow : type user struct { ID int `json:"id,omitempty"` UUID string `json:"uuid,omitempty"` Role int `json:"role,omitempty"` Name string…
Ado Ren
  • 3,511
  • 4
  • 21
  • 36
15
votes
2 answers

How to make multiple query in a very short interval / simultaneously

Hey I'm getting an error message : conn busy from pgx I don't know how to solve this. Here is my function : func (r *proverbRepo) SelectPendingProverbs(table string) (proverbs []domain.Proverb, err error) { query := fmt.Sprintf("SELECT id,…
Ado Ren
  • 3,511
  • 4
  • 21
  • 36
11
votes
2 answers

How to use 'where id in' clauses with jackc/pgx?

Does pgx offer any support for 'where in' clauses? I found in another stackoverflow thread that one should use string concatenation to build the query manually. IMO this is a bit error prone though, as you have to take care of escaping/sql injection…
u6f6o
  • 2,050
  • 3
  • 29
  • 54
8
votes
1 answer

Named prepared statement in pgx lib, how does it work?

Introduction database/sql In the Go standard sql library, the *Stmt type has methods defined like: func (s *Stmt) Exec(args ...interface{}) (Result, error) func (s *Stmt) Query(args ...interface{}) (*Rows, error) The a new (unnamed) statement is…
Tim
  • 1,585
  • 1
  • 18
  • 23
7
votes
2 answers

Bulk INSERT in Postgres in GO using pgx

I am trying to bulk insert keys in db in go here is the code Key Struct type tempKey struct { keyVal string lastKey int } Test Keys data := []tempKey{ {keyVal: "abc", lastKey: 10}, {keyVal: "dns", lastKey: 11}, {keyVal: "qwe", lastKey:…
AnswerRex
  • 180
  • 1
  • 1
  • 11
6
votes
1 answer

The pool returned by pgxpool.Connect is nil or becomes nil quickly without error

I have the following code for connecting to a Postgres database: func connectToPostgres(ctx context.Context, url string) (*pgxpool.Pool, error) { var err error for i := 0; i < 5; i++ { p, err := pgxpool.Connect(ctx, url) if…
kingkupps
  • 3,284
  • 2
  • 16
  • 28
6
votes
0 answers

pgx.ErrNoRows does not match err returned by query

New at pgx. Using pgxpool. I have a simple Query var result string err := Conn.QueryRow(context.Background(), `SELECT name FROM table WHERE id=1000`).Scan(&result) if err != nil { if err == pgx.ErrNoRows { fmt.Println("No Rows") …
Sam Dhiman
  • 61
  • 1
  • 4
5
votes
2 answers

sqlc + pgx: array of user defined enum: cannot scan unknown type (OID 16385) in text format

I'm using sqlc and pgx/v5, and getting the below error for a postgres array of a user defined enum type: Error: can't scan into dest[1]: cannot scan unknown type (OID 16385) in text format into *pgtype.Array[my-app/sqlc.Option] schema and…
user2442072
  • 437
  • 2
  • 7
  • 16
5
votes
0 answers

jackc pgx scan array

I want to scan in an array of strings using the pgx library without using pq ideally. Is there a way of doing this: sourceKeys := make([]string, 0, 1) err := rows.Scan( pq.Array(&sourceKeys), ) without using the pq library?
5
votes
3 answers

How to log queries with pgx?

I couldn't find it documentation how to log sql queries if I use pgx pool. For example I have created pool like this: func DB() *pgxpool.Pool { connStr := os.Getenv("DATABASE_URL") conn, err := pgxpool.Connect(context.Background(), connStr) …
mystdeim
  • 4,802
  • 11
  • 49
  • 77
4
votes
0 answers

How to implement nested composite types with pgx/pgtype

To avoid complex 1-to-1 mappings between Postgres tables, I thought it would be a good idea to use composite types instead. So I created these two types, and a table to hold them: CREATE TYPE my_point AS (x INTEGER, y INTEGER); CREATE TYPE…
Jonatan
  • 3,752
  • 4
  • 36
  • 47
4
votes
2 answers

How to setup pgx to get UTC values from DB?

I'm using Ent with Pgx. The column created in Postgres is: used_at timestamp with time zone NOT NULL, The value in Postgres is saved without timezone (in UTC): 2022-06-30 22:49:03.970913+00 Using this query: show timezone I get: Etc/UTC But from…
Fred Hors
  • 3,258
  • 3
  • 25
  • 71
4
votes
1 answer

Running a SELECT * FROM table query in Pgx?

I'm using PostgreSQL with , and I'm trying to run a SELECT * FROM query in Pgx. I can't seem to get the iteration down, as it only returns the last key in the table. I'm also trying to serve this as JSON on running the echo HTTP server…
Sam Morris
  • 55
  • 1
  • 5
4
votes
2 answers

Inserting empty string or null into postgres as null using jackc/pgx

I'm using an external json API that's inconsistent in the way it handles missing values. Sometimes json values show up as empty strings and other times as null. For example... Case1: datedec and curr are both empty strings. { "symbol": "XYZ", …
7rhvnn
  • 175
  • 1
  • 7
3
votes
1 answer

How to use goose migrations with pgx?

I have a small go web application that is using PostgreSQL. My database driver is pgx. Now I am at a point where I want to run migrations automatically at applications start. I found goose for that. However, I am struggling to use goose with the pgx…
ajfriesen
  • 67
  • 8
1
2 3 4 5 6 7 8