apache / apache/age

Passing agtype argument to prepared statement in Golang

Open
#2,225 1 comment 0 reactions 0 assignees View on GitHub
question
Dominant language
C
Stars
4.8k
Forks
523
Avg merge
1d 2h
Merged PRs (30d)
9

Description

Hello, I'm trying to use AGE's prepared statement to bulk insert data into my graph. To work with my Postgres database I use standard golang sql package. My code looks like this:

```go
data := ""

query := `SELECT *
FROM cypher('some_graph', $$

$$, $1)
AS (v agtype);`

stmt, err := conn.PrepareContext(ctx, query)
if err != nil {
return fmt.Errorf("error on preparing statement: %w", err)
}

_, err = stmt.ExecContext(ctx, data)
if err != nil {
return fmt.Errorf("error on executing statement: %w", err)
}

err = stmt.Close()
if err != nil {
return fmt.Errorf("error on closing statement: %w", err)
}
```

If I execute this code I get the following error:
`ERROR: invalid input syntax for type agtype (SQLSTATE 22P02)`

If I try to cast $1 to agtype in any way (for example, `$1::varchar::agtype`) I get this:
`ERROR: third argument of cypher function must be a parameter (SQLSTATE 22023)`

So I need to somehow pass my argument in a way that makes PG recognize it as agtype without any typecasting. How do I do this?

My PG version is 17 if that matters.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.