Questions tagged [pq]

Pure Go Postgres driver for database/sql

Pure Go Postgres driver for database/sql

81 questions
11
votes
1 answer

pq: function unnest(unknown) is not unique

Following code is working fine. But I want to define array['a', 'b', 'c', 'd', 'e'] as a variable. rows, err := db.Query("select colname from (SELECT date, unnest(array['a', 'b', 'c', 'd', 'e']) AS colname, unnest(array[a, b, c, d, e]) AS thing…
9
votes
4 answers

Can't import gorilla/mux (github.com/gorilla/mux@v1.7.4: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt)

In Go, I was trying simple database connection. I need to import gorilla/mux, but I couldn't. I am using VS Code. After cd ing to my project directory, I created main.go and did run go get -u github.com/gorilla/mux Here is main.go package…
user12504785
9
votes
2 answers

Query for an integer array from PostreSQL always returns []uint8

Take a simple PostreSQL db with an integer array: CREATE TABLE foo ( id serial PRIMARY KEY, bar integer[] ); INSERT INTO foo VALUES(DEFAULT, '{1234567, 20, 30, 40}'); Using pq, these values are for…
myartsev
  • 1,207
  • 2
  • 13
  • 23
9
votes
1 answer

"Operator does not exist: integer =?" when using Postgres

I have a simple SQL query called within the QueryRow method provided by go's database/sql package. import ( "github.com/codegangsta/martini" "github.com/martini-contrib/render" "net/http" "database/sql" "fmt" _…
umezo
  • 1,519
  • 1
  • 19
  • 33
8
votes
1 answer

How to stream binary data into a PostgreSQL BYTEA column using the Golang lib/pq API?

I'd like to insert some binary data into a BYTEA column, How would I go about streaming the contents of somefile.tar.gz into a table with a BYTEA column? Is it possible to stream to/from postgres from/to golang?
Akh
  • 5,961
  • 14
  • 53
  • 82
8
votes
1 answer

Why am I getting ErrNoRows("sql: no rows in result set") after inserting into postgres, even when insert was actually successful?

I am working with golang-postgres: "database/sql" _ "github.com/lib/pq" What I am doing: I run a select query. If I don't get any entry on selecting, I go ahead and insert one. Else, update, or something else... The problem is, every time insert…
Tushar
  • 1,117
  • 1
  • 10
  • 25
7
votes
1 answer

How can I check whether Psql successfully updated the record in Go

I use this driver to communicate with psql from Go. Now when I issue an update query, I have no possibility to know whether it actually updated anything (it can update 0 rows if such id is not present). _, err := Db.Query("UPDATE tags SET name=$1…
Salvador Dali
  • 214,103
  • 147
  • 703
  • 753
6
votes
1 answer

How to prepare an INSERT statement with a dynamic table name for the pq driver

How do you use a dynamic table name for a prepared INSERT statement for the pq postgres driver? At the moment I've got a test table with id SERIAL and values TEXT columns, and this statement is failing: stmt, err := db.Prepare("INSERT INTO…
Escher
  • 5,418
  • 12
  • 54
  • 101
5
votes
0 answers

jackc pgx scan array

I want to scan in an array of strings using the pgx library without using pq ideally. Is there a way of doing this: sourceKeys := make([]string, 0, 1) err := rows.Scan( pq.Array(&sourceKeys), ) without using the pq library?
5
votes
1 answer

Bindvars in golangs sqlx.DB.Select() statement requires 0 parameters

I'm using SQLX and PQ to query an SQL database with PostGress. I'm using the function Select from SQLX with bindvars but PQ panics with pq: got 1 parameters but the statement requires 0. query = ` SELECT count(*) AS count FROM…
Luis Serra
  • 131
  • 1
  • 7
5
votes
2 answers

Inserting array of custom types into postgres

I'm trying to insert a row with a column that is an array of a custom type (ingredient). My tables are: CREATE TYPE ingredient AS ( name text, quantity text, unit text ); CREATE TABLE IF NOT EXISTS recipes ( recipe_id uuid PRIMARY…
cat-t
  • 1,346
  • 1
  • 18
  • 34
5
votes
2 answers

Golang slow scan() for multiple rows

I am running a query in Golang where I select multiple rows from my Postgresql Database. I am using the following imports for my query "database/sql" "github.com/lib/pq" I have narrowed down to my loop for scanning the results into my struct. //…
Weilson Wonder
  • 111
  • 1
  • 6
5
votes
2 answers

Postgres could not determine data type of parameter $1 in Golang application

I am creating an application in Golang that uses Postgres using the pq driver. I want to make a function that can select a user-determined field from my database, but I get an error: pq: could not determine data type of parameter $1 Below is the…
Kurt Stolle
  • 322
  • 4
  • 18
5
votes
1 answer

Golang postgres Commit unknown command error?

Using postgres 9.3, go 1.6 I've been trying to use transactions with the go pq library. // Good txn, _ := db.Begin() txn.Query("UPDATE t_name SET a = 1") err := txn.Commit() // err is nil // Bad txn, _ := db.Begin() txn.Query("UPDATE t_name SET a =…
Derek
  • 11,980
  • 26
  • 103
  • 162
4
votes
2 answers

How to setup pgx to get UTC values from DB?

I'm using Ent with Pgx. The column created in Postgres is: used_at timestamp with time zone NOT NULL, The value in Postgres is saved without timezone (in UTC): 2022-06-30 22:49:03.970913+00 Using this query: show timezone I get: Etc/UTC But from…
Fred Hors
  • 3,258
  • 3
  • 25
  • 71
1
2 3 4 5 6