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
1
vote
1 answer

Inserting large object in Postgresql using jackc/pgx returns "out of memory (SQLSTATE 54000)"

I am using jackc/pgx library to insert largeobjects into Postgres. It works fine when the large objects are small. However in one case the large object was measuring almost 1.8 GB in size. As a result when performing the write operation, there was…
Swapnil17
  • 666
  • 1
  • 10
  • 22
1
vote
1 answer

inserting into postgresql decimal field fails with error "cannot convert {125.00} to Int2"

I am fairly new to golang. I am trying to insert into a postgresql table which has a numeric field, using a web app gin-gonic. postgres=# \d user_txns; Table "public.user_txns" Column | Type | Collation…
Mopparthy Ravindranath
  • 3,014
  • 6
  • 41
  • 78
1
vote
1 answer

Dynamic get query in go using pgx

So I found this: https://betterprogramming.pub/dynamic-sql-query-with-go-8aeedaa02907 it explains how to create a dynamic query for the basic sql package. I would like to do the same thing in pgx but i cant get it to work. Here is my code: func (db…
discodowney
  • 1,475
  • 6
  • 28
  • 58
1
vote
1 answer

Can't connect to PostgreSQL database using pgx driver but can using terminal

From code The code bellow outputs the following: 2022/06/21 16:01:07 Failed to connect to db: failed to connect to 'host=localhost user=postgres database=local': server error (FATAL: Ident authentication failed for user "postgres" (SQLSTATE 28000))…
mcv_dev
  • 338
  • 3
  • 14
1
vote
0 answers

Golang pgx: Update with RETURNING statement returns error when Scanning row

I use Postgres with the Postgis extension and pgx & sqlf on the Go side. Inserting/deleting and reading Rows works fine I'm just struggeling with Updates of a row since I always get this error returned from pgx when I try to scan the returned row…
JonasLevin
  • 1,592
  • 1
  • 20
  • 50
1
vote
1 answer

Go, pgx: SELECT query returns only one row

Golang, pgx: I am trying to get all rows from t_example (currently 20 items), however for some reason only one returns (the first one). I tried to debug and rows.Next() returns false after the first iteration. Could you please help me with…
Arseny
  • 21
  • 3
1
vote
1 answer

Query Go string into a jsonb argument for jsonb_set in Postgres

I am using Go and "github.com/jackc/pgx/v4/pgxpool". One of the fields in my table has json and I need to update two keys in one query. The first problem was to update several keys at once but I think it works fine now with a nested jsonb_set. A…
Don Draper
  • 463
  • 7
  • 21
1
vote
0 answers

Bulk Insert PostGis Geometry using pgx.copyFrom or pgx.Batch

I've found the way to make a bulk insert with classic postgres types from this post and it works like a charm. But for whatever reason, i struggle to make it work when trying to insert geometry points: using pgx.CopyFromRows rows :=…
Big_Boulard
  • 799
  • 1
  • 13
  • 28
1
vote
0 answers

pgx returning "conn busy" only on Delete statements

I have the following function: func DeleteReservation(roomId int32, db *pgx.Conn) error { _, err := db.Query(context.Background(), ` DELETE FROM reservation WHERE room_id = $1 `, roomId) if err != nil { …
discodowney
  • 1,475
  • 6
  • 28
  • 58
1
vote
0 answers

storing decimal into pgtype numeric

I was working with pgtype.NumRange. The lower and upper bounds are typed pgtype.Numeric. pgtype.Numeric has the following fields type Numeric struct { Int *big.Int Exp int32 Status Status NaN …
Ercross
  • 519
  • 6
  • 17
1
vote
1 answer

is it possible to connect to recovered host after failover using postgres libpq's multi-host connection string?

I have 2 db hosts: host1 and host2. I connect to db using multi host connection string: postgresql://host1:port1,host2:port2/. According to libpq documentation, connection is established with first successful host in the list given. When both hosts…
Rohanil
  • 1,717
  • 5
  • 22
  • 47
1
vote
3 answers

How to handle postgres query error with pgx driver in golang?

I read this official guide about error handling i applied it err := db.connection.QueryRow("INSERT INTO articles(uri) VALUES ($1)", article.URI).Scan() if err != nil { var pgErr *pgconn.PgError if errors.As(err, &pgErr) { …
gelerum
  • 156
  • 2
  • 11
1
vote
1 answer

How to structure my Go app for transactions via pgx

I have the following models type UsersModel struct { db *pgx.Conn } func (u *UsersModel) SignupUser(ctx context.Context, payload SignupRequest) (SignupQueryResult, error) { err := u.db.Exec("...") return SignupQueryResult{},…
Ayush Gupta
  • 8,716
  • 8
  • 59
  • 92
1
vote
1 answer

Compiling rust pgx package for another operating system

I am trying to compile rust package for timescaleDB. I am using ubuntu and I am trying to compile for centos 7. https://github.com/timescale/timescaledb-toolkit After compiling it creates two directory. One called crates. Another target>release…
kinkajou
  • 3,664
  • 25
  • 75
  • 128
1
vote
2 answers

import data into PostgreSQL and export to CSV

I am trying to do csv import and export data with postgresql (where the data base is at a remote host). Normally I would use the psql command to do \copy from ... and \copy
to ... but I need to be able to do…
ozn
  • 1,990
  • 3
  • 26
  • 37