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…
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()
…
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 *
…
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 =…
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…
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
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…
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 !=…
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,…
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…
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…
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…
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…