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
0 answers

How to get value from Count SQL statement query with pgx driver (Golang)

I failing to understand why I can not scan single value to "count" variable. Could anyone explain what am i doing wrong? Single column value is returned and I try to scan it to integer variable. query := ` SELECT COUNT('*') FROM "some-table" WHERE…
Archirk
  • 427
  • 7
  • 25
1
vote
0 answers

Golang accessing variable across same package: import cycle not allowed in test, undefined: variable

My structure is the following: In my db.go, I initialize my database package database type Database struct { Dbpool *pgxpool.Pool } var Db Database func InitDb() { dbpool, err := pgxpool.New(...) if err != nil {...} // Check for…
Leon
  • 143
  • 2
  • 9
1
vote
1 answer

How to insert foreign key related items to main table?

I'm trying to reshape/alter table. I have to create a new table and add data from related table column to main table, basically moving data from reference to main. Here is the main table as you can see it has image_pathes array column. CREATE TABLE…
Islom
  • 69
  • 8
1
vote
1 answer

What is blocking my function call in Go with pgx?

I am writing a service wherein I students from a UUID with PostgreSQL. I chose pgx (https://github.com/jackc/pgx) as a driver. I've debugged my program entirely and it seems that nothing is called after I call row.Scan. My connection is working and…
reb0und
  • 23
  • 2
1
vote
1 answer

Error while trying to open sql connection via pgx

I have some strange issue. Try to connect to sql db by pgx driver, but error: can't open db conn: sql: unknown driver "pgx" is occured. I can't find any answer for this issue, maybe I failed in some cfg? Here is code: import ( "database/sql" …
SloVaC
  • 21
  • 2
1
vote
0 answers

can't scan into dest[2]: cannot scan int4 (OID 23) in binary format into *models.User

type Order struct{ Id uint `json:"id"` Items []Item Total float64 CustomerID int32 Address Address CreatedAt time.Time UpdatedAt time.Time Status orderstatus } query := INSERT INTO…
1
vote
0 answers

golang postgresql: Get query results as comma separated values (csv format)

I'm trying to get results from select query in a comma separated format (don't want results in a file). Following code works fine if I use stmt := fmt.Sprintf("SELECT * FROM table") but below code fails to reproduce any results because rows.Next()…
1
vote
1 answer

Why pgx returns connection busy on commit?

I have a function to insert values to the table in bulk. tx.Commit() returns conn busy. As I got from reading code is that conn.Begin() actually makes it busy. So the question is how to do this correctly? Should I use transactions together with…
Yura
  • 969
  • 14
  • 33
1
vote
0 answers

Cannot unmarshal string into Go struct field * of type pgtype.Range[github.com/jackc/pgx/v5/pgtype.Date]

I have problems to scan json objects which include daterange types: Let's assume these tables: CERATE TABLE first_table ( id int PRIMARY KEY, name text ); CERATE TABLE second_table ( id int PRIMARY KEY, title text, period daterange NOT…
Emaborsa
  • 2,360
  • 4
  • 28
  • 50
1
vote
0 answers

Can i use Query() func twice in pgx Golang lib?

I use query to Find All DB data, and one of tables need to be array, so i integrated the loop. EveryTime errors is conn is busy. ` for rows.Next() { var ord Order err = rows.Scan( and after one more Query() which is uses to find all…
SloVaC
  • 21
  • 2
1
vote
1 answer

pgx copyfrom with WHERE condition

I would like to use pgx (via sqlc) copyfrom feature with a COPY FROM WHERE condition as such: (this condition was taken from a working rule on INSERT): WHERE (EXISTS ( SELECT * FROM asns WHERE merchantId IS NOT…
Reneli
  • 1,756
  • 2
  • 16
  • 26
1
vote
2 answers

How to check for custom Postgres exceptions raised via RAISE EXCEPTION in Golang?

I'm using Postgres with Golang via pgx I've a trigger function something like the following: CREATE OR REPLACE FUNCTION foo() RETURNS TRIGGER AS $$ BEGIN IF (bar = 'baz') THEN -- something ELSE RAISE EXCEPTION 'oops error'; …
Abhijit
  • 468
  • 8
  • 22
1
vote
1 answer

Using an in-memory db with pgx and bun (Golang)

I have just started using pgx and bun with Golang and I need to start testing my repository implementation. I am struggling to understand if I can use an embedded postgres db and what would be the best choice. Any suggestion is more than…
panza
  • 1,341
  • 7
  • 38
  • 68
1
vote
1 answer

How to write a go connection string for pgx.pool to a remote RDS?

I have no trouble connecting go pgxpool to a postgresql database in a docker container but can't figure out how to write a connection URL string for a linode postgresql RDS. Specifically, what is the first part of the URL "postgres://"? I can't find…
markhorrocks
  • 1,199
  • 19
  • 82
  • 151
1
vote
0 answers

Failed to assert PGX error using PGconn and PGX

rows, err:= b.DB.ExecContext( ctx, fmt.Sprintf(` UPDATE service_slots SET slots_left = slots_left - %d WHERE date = $1 AND …