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
0
votes
1 answer

Using jsonb_agg/jsonb_build_object to parse to inner structs

Whenever I try to get (select/scan) the Groups (outer struct) along with their Collaborators (inner structs), I'm getting the following error : // sql: Scan error on column index ..., name "collaborators": unsupported Scan, storing driver.Value type…
BVtp
  • 2,308
  • 2
  • 29
  • 68
0
votes
0 answers

SQL table name as variable to query

I am using the pgx library to populate a Postgres database in Go. Following e.g. the tutorial here and this question, I construct my query like so: // this works tblinsert = `INSERT into tablename (id, body) VALUES ($1, $2) RETURNING id` var id…
patrick
  • 4,455
  • 6
  • 44
  • 61
0
votes
1 answer

Create TimescaleDB hypertable using golang batch query

My golang service needs to create a hypertable dynamically in Timescale DB. I use pgx driver. My code is the following (I removed an error handling): func (s *Storage) CreateHyperTableBatch(ctx context.Context, tableName string) error { …
Yura
  • 969
  • 14
  • 33
0
votes
1 answer

How to convert string to sqlx.types.JSONText?

I am using gqlgen, sqlx and pgx. Trying to use custom scalar to store as jonb type in postgres database. // graph/model/item.go type Attributes types.JSONText // Marshal here ... func (a *Attributes) UnmarshalGQL(v interface{}) error { switch…
Swix
  • 1,883
  • 7
  • 33
  • 50
0
votes
1 answer

Error when scanning Postgres float4: cannot assign 5000 into pgtype.Float4

Query: `select "number" from "person"` Here is the code where am iterating over a row. number is of type float4 in Postgres. I am using pgtype.Float4 for scanning. for rows.Next() { var number pgtype.Float4 err :=…
dclipca
  • 1,739
  • 1
  • 16
  • 51
0
votes
0 answers

Cannot use (pgx.Identifier literal) (value of type pgx.Identifier) as pgx.Identifier value in argument

This code: func DoStuff(input []Resource) { rowsToken := [][]interface{}{} for _, data := range input { rowsToken = append(rowsToken, []interface{}{data.TokenID, data.Class}) } _, err := IDB.CopyFrom(ctx,…
Gabriel
  • 5,453
  • 14
  • 63
  • 92
0
votes
1 answer

How to open db connection only when there's request in golang

So what I'm gonna do is try to open db connection when there's is http request, and close again. I'm using pgx and gin package so here's what I do : func handleGetUsers(c *gin.Context) { connectDB() data, err := allUsers() if err != nil { …
Aldy Yuan
  • 1,795
  • 9
  • 23
0
votes
1 answer

Scan pgx rows for stdout

I just started to work with golang/pgx and I need to scan all columns simply to send them to stdout. Obviously, there is no schema known at compile time nor the structure to scan. Any chance I can do it with pgx or any other golang/pgsql driver?
0
votes
0 answers

Migrating from lib/pq to jackc/pgx

After migrating project to "github.com/jackc/pgx/pgxpool" I have an error on every query: expected 0 arguments, got 1 I noticed that error occurs at Scan Here is simple code block: sql := `SELECT location FROM tb_champ WHERE is_active = true LIMIT…
Romowski
  • 1,518
  • 5
  • 25
  • 50
0
votes
1 answer

How to use a variable to fetch different table with pgx driver?

Here is a function to fetch for french proverbs : func (r *proverbRepo) SelectFrByDegree(search string) (proverbs []domain.Proverb, err error) { rows, err := r.Db.Query(context.Background(), `SELECT ID, proverb FROM proverbs_fr …
Ado Ren
  • 3,511
  • 4
  • 21
  • 36
0
votes
1 answer

How to convert pgtype.Int4Array (from pgx library) to []int64 Golang type?

I use Go and Postgres (with pgx driver) In my Postgres table I have a field with array of integers. I have created a variable to store array of integers after scanning. var ids pgtype.Int4Array How to convert ids to []int64?
Klimbo
  • 1,308
  • 3
  • 15
  • 34
-1
votes
1 answer

Why does rows.Next() depends on DB response rate?

I'm using sqlx, pgx and postgresql. There are two DB`s. First - based on VPS server (slow one), second - installed locally on my PC (fast one). I have a question about this code: var ordersSlice []OrdersModel start := time.Now() query = `select…
Metamorphosis
  • 179
  • 1
  • 12
-2
votes
1 answer

golang runtime error when i am trying to use db.QueryRow

i have controller.go: package controller import ( "github.com/fishkaoff/todoList/pkg/postgresql" "github.com/gin-gonic/gin" "net/http" "context" ) type Task struct { Title string Description string } func GetTasks(c…
fishkaoff
  • 19
  • 3
-2
votes
1 answer

query is returning "expected 0 arguments, got 1"

I am trying to query a database that I know has data in it from directly querying within pgadmin. When I query using the following code it returns no results: const DATABATE_URL = "postgres://postgres:pw@localhost:5432/postgresdb" conn, err :=…
SomethingsGottaGive
  • 1,646
  • 6
  • 26
  • 49
1 2 3 4 5 6 7
8