Questions tagged [pq]

Pure Go Postgres driver for database/sql

Pure Go Postgres driver for database/sql

81 questions
1
vote
1 answer

sql.Scan not returning ErrNoRows error when it should

I have a function GetAccount which is generated by sqlc. When I call GetAccount(/*unused id*/), An ErrNoRows error should be returned. Instead I am getting no error and an Account with default values (zeros and empty strings) returned. GetAccount…
SSMSJM
  • 149
  • 6
1
vote
1 answer

pq statement preparation returns a no encryption panic

I'm testing a database insert statement similar to the following which works locally but not after deployment to a kubernetes cluster connected to a managed database host: func Insert(w http.ResponseWriter, r *http.Request) { db := dbConn() …
eomolo
  • 61
  • 5
1
vote
0 answers

(Golang)How to call function postgres output REFCURSOR in golang ("github.com/lib/pq")

i don't know how to call function with output REFCURSOR in golang My function create function find_all_by_user_id(OUT rc_out refcursor, p_user_id bigint) returns refcursor language plpgsql as $$ BEGIN open rc_out for select * …
htan
  • 79
  • 6
1
vote
0 answers

How to use time.Time in a postgres query?

I am using pq library in golang for postgres queries. I want to pass timestamp in the query string. Ex. query = 'SELECT \* FROM table WHERE ts \<= NOW() - interval '5 seconds'' Instead of NOW() ...can I pass a timestamp? Ex. t=time.Now() query =…
nrao
  • 31
  • 1
1
vote
1 answer

golang pq sql driver: pq: invalid input syntax for type uuid error type

I'm trying to handle Postgres error. If user sends invalid uuid - Postgres returns an error with message: pq: invalid input syntax for type uuid:... So, i want to check that error and if the error equals to the invalid input syntax error - i would…
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
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

how to batch insert and get results by sqlx in postgres

it's easy to insert one record and get result like this: s := "INSERT INTO quiz_answer_details (quiz_answer_id, question_id, type, choices, content) VALUES ($1, $2, $3, $4, $5) RETURNING *" d, err := fromQuizAnswerDetail(in) if err !=…
nullne
  • 511
  • 6
  • 12
1
vote
1 answer

Error executing query with parameters in golang with postgres driver

I created a func that execute query on postgres database. I use the driver github.com/lib/pq but if I run this: _, err := repository.db.ExecContext(ctx, query, args...) where query is INSERT INTO fakeclients (uuid, name, last_name, birth_day,…
Jacob
  • 120
  • 7
1
vote
1 answer

Unable to connect to postgresql using Go and pq

I'm trying to connect a Go application with postgresql. The app import postgresql driver: "crypto/tls" "database/sql" "fmt" "log" "os" "os/signal" ... _ "github.com/go-sql-driver/mysql" _ "github.com/lib/pq" _ "github.com/mattn/go-sqlite3" and…
Teddy Kossoko
  • 1,168
  • 3
  • 20
  • 48
1
vote
1 answer

pass more than enough arguments to lib/pq

To simplify the code, and prevent from passing similar arguments again and again, I created a method Put for some structures as below. For example, the reason why UID is not used here is because UID was set as an auto increase value. type User…
1
vote
1 answer

Data types between PostgreSQL and Golang

type User struct { Email string `json:"email"` Password string `json:"password"` } db, err := sql.Open("postgres", os.Getenv("DATABASE_URL")) if err != nil { log.Fatal(err) } fmt.Println("email: ",…
Nathan Takemori
  • 139
  • 1
  • 10
1
vote
1 answer

Converting argument $1 type: unsupported type []interface {}, a slice of interface

I try to query on list of userIDs. I am using the Go Pq library. func ListUsers(userIDs []interface{}) (users []User, err error) { stm := `SELECT U.id, ( CASE WHEN TRIM(UP.first_name || ' ' || UP.last_name) = '' THEN U.id :: TEXT…
Idoncare
  • 15
  • 1
  • 1
  • 10
1
vote
0 answers

sql: expected 0 arguments, got 2

I'm struggling to properly utilize sqlx and the pq driver for Postgres to create a row in the database. Let's start simple: I have a user, role and user_role table. I want to insert a role into the database and get the ID of the inserted row. This…
LuMa
  • 1,673
  • 3
  • 19
  • 41
1
vote
1 answer

How to get column name for a unique_constraint violation?

I am using the pq driver and I'm wondering why the pq.Error gives an empty Column when I face a unique constraint violation. I could parse Detail but is there any reason why Column would be empty? It would be preferable if I could just get email…
user1354934
  • 8,139
  • 15
  • 50
  • 80