2

I'm trying to use the golang driver for apache age to run cypher queries on Windows. For the postgres server I'm using the the Apache-Age docker image.

While running the sample, I get the following error:

ahmar> go run main.go age_wrapper_sample.go sql_api_sample.go  
# Do cypher query with Age API
SELECT * FROM age_prepare_cypher($1, $2); testGraph CREATE (n:Person {name: '%s'})
panic: pq: function age_prepare_cypher(unknown, unknown) does not exist

goroutine 1 [running]:
main.doWithAgeWrapper({0x1004e94?, 0xc00000a018?}, {0xff0efb?, 0x1?})
        C:/Users/ahmar/Desktop/GOlang drivers/samples/age_wrapper_sample.go:43 +0xcb4
main.main()
        C:/Users/ahmar/Desktop/GOlang drivers/samples/main.go:41 +0x77
exit status 2

The queries are working fine when I run them on the postgres server directly. Also other age commands like LOAD 'age'; etc, are working from the driver but the ExecCypher() function is not working.

The error seems to be originating from the age.go file in execCypher(), when the age_prepare_cypher() function is called.

Note: I'm not facing this error on Linux. There, the queries are working fine when using the age go driver and I'm getting the expected output.

Ahmar
  • 584
  • 2
  • 7

2 Answers2

1

The function age_prepare_cypher was added recently in this commit. It's not added to the image apache/age:v1.1.0. So if you run the sample at the commit 42f94e7f36dc084b74ec335536a18173c6fca4cd and connect to the database provided by the image apache/age:v1.1.0, you will get the error panic: pq: function age_prepare_cypher(unknown, unknown) does not exist.

I run the container with this command:

docker run \
    --name age  \
    -p 5432:5432 \
    -e POSTGRES_USER=postgres \
    -e POSTGRES_PASSWORD=agens \
    -e POSTGRES_DB=postgres \
    -d \
    apache/age:v1.1.0

And then run the sample at the commit 42f94e7f36dc084b74ec335536a18173c6fca4cd without any change:

$ go run main.go age_wrapper_sample.go sql_api_sample.go
# Do cypher query with SQL API
SELECT * FROM age_prepare_cypher($1, $2); testGraph CREATE (n:Person {name: '%s', weight:%f})
panic: pq: function age_prepare_cypher(unknown, unknown) does not exist

You see that the sql_api_sample fails first; while in your question, only the age_wrapper_sample fails. So it seems that you have modified the source code and the two examples connect to different databases. Please check carefully which database the failed example connecting to, and see whether the function is defined in that database. You can check the existence of a function with \df. Here is the output when the functions is not found:

postgres=# \df ag_catalog.age_prepare_cypher
                       List of functions
 Schema | Name | Result data type | Argument data types | Type 
--------+------+------------------+---------------------+------
(0 rows)

If this is not the case, please describe the exact steps to reproduce the issue. Thank you!

Zeke Lu
  • 6,349
  • 1
  • 17
  • 23
  • I actually changed the order of execution of age_wrapper_sample and sql_api_sample but I think both the examples connect to the same database since the 'dsn' is defined in main.go. I checked and the age_prepare_cypher function was not present in the database. I actually switched to a newer docker image and it has the age_prepare_cypher function so the Go Driver commands are working now. Thanks for the detailed answer. – Ahmar Apr 01 '23 at 07:34
1

You might be using an old docker image which does not have age_prepare_cypher() function. I tested the go driver sample on windows using the latest docker image and it was working fine.

go run main.go age_wrapper_sample.go sql_api_sample.go                                                                     ﳑ00:52:12  
# Do cypher query with SQL API
844424930131969 Person map[name:Joe weight:67.3]
844424930131970 Person map[name:Jack roles:[Dev marketing] weight:77.3]
844424930131971 Person map[name:Andy weight:59]
V{id:844424930131970, label:Person, props:map[name:Jack roles:[Dev marketing] weight:77.3]} E{id:1125899906842625, label:workWith, start:844424930131970, end:844424930131969, props:map[weight:3]} V{id:844424930131969, label:Person, props:map[name:Joe weight:67.3]}
V{id:844424930131971, label:Person, props:map[name:Andy weight:59]} E{id:1125899906842626, label:workWith, start:844424930131969, end:844424930131971, props:map[weight:7]} V{id:844424930131969, label:Person, props:map[name:Joe weight:67.3]}
V{id:844424930131969, label:Person, props:map[name:Joe weight:67.3]} E{id:1125899906842625, label:workWith, start:844424930131970, end:844424930131969, props:map[weight:3]} V{id:844424930131970, label:Person, props:map[name:Jack roles:[Dev marketing] weight:77.3]}
V{id:844424930131969, label:Person, props:map[name:Joe weight:67.3]} E{id:1125899906842626, label:workWith, start:844424930131969, end:844424930131971, props:map[weight:7]} V{id:844424930131971, label:Person, props:map[name:Andy weight:59]}
ROW  1 >> 
         V{id:844424930131969, label:Person, props:map[name:Joe weight:67.3]}
         E{id:1125899906842625, label:workWith, start:844424930131970, end:844424930131969, props:map[weight:3]}
         V{id:844424930131970, label:Person, props:map[name:Jack roles:[Dev marketing] weight:77.3]}
.....

I also checked that age_prepare_cypher() function is present in this docker image.

postgresDB=# \df ag_catalog.age_prepare_cypher
                                List of functions
   Schema   |        Name        | Result data type | Argument data types | Type
------------+--------------------+------------------+---------------------+------
 ag_catalog | age_prepare_cypher | boolean          | cstring, cstring    | func
(1 row)
Sarthak
  • 380
  • 7