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

Too many arguments in call to "github.com/jackc/pgx".Connect

I am trying to open a connection to a postgres database using pgx and I am getting the following error: ./dbservice.go:12:26: too many arguments in call to "github.com/jackc/pgx".Connect have (context.Context, string) want…
SomethingsGottaGive
  • 1,646
  • 6
  • 26
  • 49
1
vote
0 answers

pgx preparedStatement execution does not return results (unlike fmt.Sprintf)

For some reason, the prepareStatement I built in go using pgx is not returning any results/rows (see scenario1). In scenario 2, if I build the same query using Sprintf and $, the results are also not returned. But, as shown in scenario 3, if I build…
JonyD
  • 1,237
  • 3
  • 21
  • 34
1
vote
0 answers

go postgres refactoring pq CopyIn to pgx CopyFrom

I'm trying to refactor code so that I will connect to postgres DB using pgx, not pq. I've tried a lot of things, but I keep getting the ERROR: incorrect binary data format (SQLSTATE 22P03). Please find below both the original working code and my…
moratsam
  • 41
  • 3
1
vote
1 answer

Postgres table batch updates using golang pgxpool not reflected in database

I need to update a rather large psql table with newly transformed ID's (passed in as 'records'). I created this function below to utilize pgxpool's connection pool and request batching, if I apply these transactions using a different client they…
Willeman
  • 720
  • 10
  • 24
1
vote
1 answer

What is the correct/idiomatic way of handling possible null values from a database query?

I'm handling a many-to-many relationship in Go. For this, I'm using the pgx PostgreSQL driver. For the sake of keeping this question as simple as possible, let's assume a simple blog post that can have some tags: CREATE TABLE IF NOT EXISTS tag ( …
idix
  • 433
  • 1
  • 6
  • 13
1
vote
1 answer

interface {} is string, not []uint8 when scanning PostGIS Point from Postgres using pgx

I have a database with a buildings table which contains a coordinate column of type GEOMETRY(POINT, 4326). With the hope to read the coordinates, I wrote the following code: rows, err := db.pool.Query(context.Background(), `select "uuid",…
dclipca
  • 1,739
  • 1
  • 16
  • 51
1
vote
1 answer

SSL connection to Google Cloud Postgres

I have migrated my postgres database to Google Cloud SQL. Without SSL enabled I can connect with no issues. However I am struggling to get the SSL connection working. I am using the pgx pool driver. I have downloaded the server, client and private…
eurosoll
  • 41
  • 6
1
vote
0 answers

pgx says I violate not-null constraint despite having DEFAULT NOW()

So I have this table: CREATE TABLE customer ( id SERIAL PRIMARY KEY, name character varying(30) NOT NULL, created_at timestamp with time zone NOT NULL DEFAULT NOW() ); And I have github.com/jackc/pgx/v4 in my import statement. My Go…
Adam
  • 2,948
  • 10
  • 43
  • 74
0
votes
0 answers

Using Bob SQL Access Toolkit with pgx's conneciton pool implementation

I'm evaluating Bob SQL Access Toolkit for a new project. I would like to also use the pgx connection pool implementation. This is what I have so far in order to integrate the libraries (error handling removed): ctx := context.Background() pool, err…
x80486
  • 6,627
  • 5
  • 52
  • 111
0
votes
1 answer

How to scan a boolean, which may be NULL?

I try to scan a boolean result into a boolean pointer: var expired bool db.QueryRow(context.Background(), sql, id, n).Scan(&expired) The code fails with the following error: can't scan into dest[0]: cannot scan NULL into *bool Which Go type do I…
ceving
  • 21,900
  • 13
  • 104
  • 178
0
votes
0 answers

How to use batching to optimise runtime with the Pgx package in Golang

I am trying to improve the runtime of my golang code. I am very still quite new to Golang so please forgive my slightly messy code. I am iterating over a very large number of files, compare the file information and create a new struct with the…
Sebastian
  • 61
  • 6
0
votes
1 answer

Update or insert (gen_random_uuid) if no UUID is provided

Suppose I create a table of tasks. CREATE TABLE todos ( id UUID DEFAULT gen_random_uuid PRIMARY KEY, text STRING(1000) ) An end-user creates some new todos (which don't yet have an id/UUID) and updates others, and we'd like to be able to update…
dgh
  • 8,969
  • 9
  • 38
  • 49
0
votes
0 answers

Why call rows.Close() could take long time in pgx?

Why call rows.Close() takes too long time when I call it after I exit from loop rows.Next() before processing all elements of loop. Its happen when I make request which returns huge amount of data (around 300 000 rows). This problem doesn't exists…
StasVo
  • 554
  • 6
  • 6
0
votes
0 answers

Correct way to use Go Pprof to compare execution-time differences in two versions of a same functionality

I am running a Golang project in a container environment which has two pods. Pod1: user-interaction and data-access layer. Pod2: Database server. The data-access layer involves functions like data validation, do get on db to check if data already…
Harish Reddy
  • 65
  • 1
  • 6
0
votes
1 answer

pgxpool and multi-tenancy BeforeAcquire/AfterAcquire

I'm trying to use postgres user variables to handle multi-tenancy through RLS. However, for performance I want my webapp to use the pg connection pool. I came across this thread: https://github.com/jackc/pgx/issues/288#issuecomment-901975396 and…
Trent
  • 2,909
  • 1
  • 31
  • 46