My code is set up such that every time I want to make a query I open the DB, run QueryRow(), Scan the results into variables, and then close the DB and rows using defer. However, I'm getting a connection leak though I believe I've closing all of…
I'm learning to use PostgreSQL and GORM. Trouble came relatively quickly, and it feels as if I'm the only one having this problem ever.
Here, I'm creating a struct, instantiating it, and trying to write it to database. However, it returns an…
I'm using the createUsers func to populate my fake DB, just for tests.
I'm using the bulk imports feature of pq (https://godoc.org/github.com/lib/pq#hdr-Bulk_imports).
func createUsers() {
users := []models.User{}
for i := 0; i < 10; i++…
I have a table with an interval column, something like this.
CREATE TABLE validity (
window INTERVAL NOT NULL
);
Assume the value stored is 'P3DT1H' which is in iso_8601 format.
When I try to read the value, it comes in regular postgres format.…
query := "WITH b(ColA, ColB) AS (VALUES ($1,$2)) UPDATE schema_name.table_name AS a SET ColC = b.ColB FROM b WHERE a.ColA = b.ColA AND a.ColB = b.ColB"
res, err := db.Exec(query, 1, 1)
The above code fails with the following error:
pq: operator…
I'm having this issue
db, err := sql.Open("postgres", "user=xxx dbname=xxx connect_timeout=5 sslmode=disable")
if err != nil {
log.Fatal(err)
}
I have no postgres installed on my localhost so sql.Open should return some error but actually…
I want to do math with the pq-formula but for some reason everything works except that the numbers are different then they should be.
The Formula that I want to represent is:
x1,2 = -p/2 ± √(p^2/4 -q)
If I do the Math with a calculator and not with…
I am setting up a local Postgres database on Docker with the postgres:14-alpine image, and running database migrations on it with golang-migrate, when I got the following error message after running the migrate tool:
error: pq: role "root" does not…
I created a Custom Function to get running total with 3 variables as below.
(SourceTable as table, ColumnName, optional NewAddedColumnName as text) =>
let
Add_Index = Table.AddIndexColumn(SourceTable, "Index", 1),
Get_RT =…
Can Power query do this?
So I have a group of parent IDs. If the parent Ids are the same but the values from the corresponding attributes are different, I want PQ to let me know they can be grouped together.
Here is the example.
So Parent IDs…
I have a list of item type and item numbers like follows:
items := models.ItemKeys{
ItemKeys: []models.ItemKey{
{
ItemType: "type1",
ItemNumber: "10347114",
},
{
…
I would like to replace values in a columns from corresponding values in another table avoiding merging and expanding columns.
Data which I want to send to another table:
Table where I want to replace data:
As you can see I have 2 tables but they…
I am making a simple CRUD app with Golang using a postgres database hosted on my computer. I am using the sql driver https://github.com/lib/pq.
I am able to successfully store users in the database from a POST request with the following code
func…
I'm trying to follow Gorm's documentation to create a generated field, defined by a function:
type Foo struct {
ID int64 `json:"id"`
AmountOfBars string `json:"amount_of_bars" gorm:"default:amount_of_bars()"`
}
type RelatedBar…
I was just wondering how to deal with eager loading queries to retrieve data with several associations, let me explain my models:
type User struct {
Id uint
Name string
Username string
Image string
}
type Post struct {
Id unit
Content…