0

I'm trying to query data from HP Vertica 6 using libpq: SELECT * FROM columns WHERE table_name=?

and getting the error back: ERROR: Syntax error at or near "EOL" LINE 1: ...FROM columns WHERE table_schema=? ^

I also tried $1 instead of ?, but it did not recognize it as parameter. Why?

Terry
  • 310
  • 3
  • 9
  • Doesn't seem like you're preparing the statement correctly. – Kermit Jun 21 '14 at 18:04
  • Thank you! I did not know that statement must be prepared before passing parameters. I have only experience with Postgres, and just starting working with Vertica. I'm using libpq compiled from Postgres 9.0 source. – Terry Jun 21 '14 at 19:52
  • When I prepared the statement by PQprepare, and executed it by PQexecPrepared, I got "ERROR: Insufficient data left in message". The same code works with Postgre, but not with Vertica... What could be a possible reason? res = ::PQprepare(conn, preparedQueryName, sCommandText.c_str(), nParams, paramTypes); if (::PQresultStatus(res) == PGRES_COMMAND_OK || strcmp(::PQresultErrorField(res, PG_DIAG_SQLSTATE), "42P05") == 0) { ::PQclear(res); res = ::PQexecPrepared(conn, preparedQueryName, nParams, paramValues, paramLengths, paramFormats, 0, 0); } – Terry Jun 21 '14 at 19:55

1 Answers1

1

I found the way to pass parameters to Vertica from a C++ application! First, the statement should be prepared. Second, correct type numbers should be used (not the default numbers defined for the Postgres/libpq). Examples of the type numbers:

PGTYPE_INT8             = -5,
PGTYPE_INT2             = 5,
PGTYPE_INT4             = 4,
PGTYPE_TEXT             = -1,
PGTYPE_FLOAT4           = 7,
PGTYPE_FLOAT8           = 8,
PGTYPE_VARCHAR          = 12,
PGTYPE_DATE             = 91,
PGTYPE_TIME             = 92,
PGTYPE_TIMESTAMP        = 93,
PGTYPE_NUMERIC          = 2,
Terry
  • 310
  • 3
  • 9