Search code examples
c++cpostgresqllibpq

Inserting a point via libpq with pgexecparams


I'm trying to insert a point into a Postgresql table with c++. This is what I have so far:

const char * paramValues[1];
paramValues[0] = "{100,200}";
res = PQexecParams(conn, "insert into test (pt) values ($1::point)", 1, NULL, paramValues, NULL, NULL, 0);

It gives the error: "invalid input error for type point"

What should I be using instead of {100,200}? I've also tried paramValues[0] = "point(100,200)";


Solution

  • paramValues[0] = "100,200"; does the trick.

    I'll also add for composite types, a ( and ) goes around the values like so: paramValues[1] = "(10.25, some name)" which would represent a type created with create type foo (some_real real, some_name varchar(100))