You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@age.apache.org by "P34K1N (via GitHub)" <gi...@apache.org> on 2025/09/24 07:36:18 UTC

[I] Passing agtype argument to prepared statement in Golang [age]

P34K1N opened a new issue, #2225:
URL: https://github.com/apache/age/issues/2225

   Hello, I'm trying to use AGE's prepared statement to bulk insert data in my graph. To work with my Postgres database I use standard golang sql package. My code looks like this:
   
   ```go
   data := "<some data as serialized JSON>"
   
   query := `SELECT *
   FROM cypher('service_graph', $$
   	<some code>
   $$, $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?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@age.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Passing agtype argument to prepared statement in Golang [age]

Posted by "nikoraes (via GitHub)" <gi...@apache.org>.
nikoraes commented on issue #2225:
URL: https://github.com/apache/age/issues/2225#issuecomment-3686931792

   I had to fork and fix the C# library to make this work. 
   My guess is that this may not be (or wrongly) implemented in other drivers as well.
   
   The 'version byte' was crucial ...
   [AgtypeConverter.cs](https://github.com/konnektr-io/npgsql-age/blob/c310a3b7ed81da80521437eb71b080ecba97efb9/src/Npgsql.Age/Internal/AgtypeConverter.cs#L50-L65)
   [NpgsqlAgeExtensions.cs](https://github.com/konnektr-io/npgsql-age/blob/c310a3b7ed81da80521437eb71b080ecba97efb9/src/Npgsql.Age/NpgsqlAgeExtensions.cs#L166-L188)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@age.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org