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

pgx tls connection throws client cert invalid error for valid cert

I'm trying to use pgx to make a TLS connection to a postgres 10 db. My connection string is similar to: "host='my-host.com' port='5432' dbname='my-db' user='my-db-user' sslmode='verify-full' sslcert='/path/to/db_user.crt'…
xgord
  • 4,606
  • 6
  • 30
  • 51
0
votes
2 answers

How to write an unit test for a handler that invokes a function that interacts with db in Golang using pgx driver?

I've been trying to write unit tests for my http handler. The code segment is as below: func (s *Server) handleCreateTicketOption(w http.ResponseWriter, r *http.Request) { var t ticket.Ticket body, err := ioutil.ReadAll(r.Body) if err !=…
tassador
  • 19
  • 3
0
votes
0 answers

How to get RETURNING ID

golang-1.18.1, postgresql-12 ... var fk = []int{11, 22} var img = []string{"a", "b"} var prim = []string{"a1", "b1"} err = conn.QueryRow(context.Background(), "INSERT INTO tb (fk, img, prim) VALUES($1,$2,$3),($4,$5,$6)",…
Alex
  • 150
  • 1
  • 10
0
votes
1 answer

Create User in postgres with pgx (SQLSTATE 42601)

I am trying to create a user in postgres. currently trying to use https://github.com/jackc/pgx as the driver to connect to the db. I have the below package main import ( "context" "fmt" "os" "github.com/jackc/pgx/v4" ) func main()…
Moulick
  • 4,342
  • 1
  • 13
  • 19
0
votes
0 answers

Higher than expected latency in GO/Postgres Connection

I'm seeing higher than expected latency when I query postgres from my Go application. Below is a working example, using a publicly accessible DB. When I run the below code, I get a response in 800ms. When I run the same query directly in my sql…
samester
  • 21
  • 4
0
votes
2 answers

Go and pgx: cannot convert [+11111111111] to Text

I'm new to golang and pgx and I'm running into an issue when I try to run a simple query. I have the following table in postgres. CREATE TABLE users ( user_id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY, phone_number TEXT NOT NULL…
sgonzalez
  • 741
  • 6
  • 20
0
votes
0 answers

Cannot use logrusadapter.NewLogger(logrusLogger) (value of type *logrusadapter.Logger)

I'm following this SO question to implement a logger into my pgx connection since I'm getting a closed pool error on Scan. I'm getting this error in vscode. cannot use logrusadapter.NewLogger(logrusLogger) (value of type *logrusadapter.Logger) as…
markhorrocks
  • 1,199
  • 19
  • 82
  • 151
0
votes
2 answers

Returning id in simple postgresql query using pgx and go

I'm trying to run this simple query to return the id, according to the author we use the QueryRow function, ok, but this query result returns a expects 2 args but received 3 error somewhere in here. querymodel.go type WidgetetModel struct { DB…
Spencer Hire
  • 735
  • 3
  • 14
  • 32
0
votes
2 answers

Setting a DialFunc for pgxpool.Config

I am having trouble creating a connection to a postgres database via ssh tunneling with the "github.com/jackc/pgx/v4/pgxpool" library. I cannot seem to figure out how to set the DialFunc for the *pgxpool.Config that I would like to use to establish…
0
votes
1 answer

DELETE with ANY clause not working as expected

I'm trying to DELETE certain rows in my Postgress DB using the ANY clause. Here's the structure - ---- TABLE A ----- ------------------- rId UUID NOT NULL, oId UUID NOT NULL, eId UUID NOT NULL, --- PRIMARY KEY (rId, oId,…
GopherGopher
  • 376
  • 1
  • 2
  • 16
0
votes
1 answer

How to use postgres intervals in go?

I have a go project that connects to a postgres database. I want to delete orders over a certain number of days - I have tried doing it like this: type SQLOrderDatabase struct { Connection *pgx.Conn logger *logrus.Entry } interval…
Nespony
  • 1,253
  • 4
  • 24
  • 42
0
votes
1 answer

How to present dynamic keys in a type struct?

I have a PostgreSQL table which has a JSONB filed. The table can be created by create table mytable ( id uuid primary key default gen_random_uuid(), data jsonb not null, ); insert into mytable (data) values ('{ …
Hongbo Miao
  • 45,290
  • 60
  • 174
  • 267
0
votes
0 answers

parsing query values to substruct using pgx

Prefacing this that im very new with Go and pgx. Is there a way to easily parse substruct values from a query? So I do a Join query like: rows, err := conn.Query(context.Background(), `SELECT rdr.id AS r_Id, rdr.field1 AS…
discodowney
  • 1,475
  • 6
  • 28
  • 58
0
votes
2 answers

Connecting to postgres on google cloud VM instance with golang?

I'm using Golang (github.com/jackc/pgx/v4) to try and connect to my compute engine VM instance, but not having any luck, "Unable to connect to database: failed to connect to host=[IP] user=postgres database=postgres: dial error (dial tcp…
wes kay
  • 97
  • 1
  • 8
0
votes
0 answers

Go API on Google App Engine with Postgres

I am trying to connect to my GAE Postgres SQL db using Go+Gin+PGX. I have the Postgres SQL api activated and this program runs on my local machine but does not run on GAE. I think it is not connecting the db via pgx but I am not sure. main.go works…
Bryce Wayne
  • 351
  • 5
  • 17