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…
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…
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…
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"
_…
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?
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…
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…
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…
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?
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…
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…
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.
//…
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…
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 =…
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…