Using `SELECT EXISTS`
#1427
-
How should I go about executing a statement that looks like this: |
Beta Was this translation helpful? Give feedback.
Answered by
jackc
Dec 16, 2022
Replies: 1 comment 1 reply
-
Works for me: package main
import (
"context"
"log"
"os"
"github.com/jackc/pgx/v5"
)
func main() {
ctx := context.Background()
conn, err := pgx.Connect(ctx, os.Getenv("DATABASE_URL"))
if err != nil {
log.Fatal(err)
}
defer conn.Close(ctx)
var b bool
err = conn.QueryRow(ctx, "select exists(select 1 from pg_type where typname = 'int4')").Scan(&b)
if err != nil {
log.Fatal(err)
}
log.Println(b)
} Output:
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
lukewhrit
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works for me:
Output: