kou commented on code in PR #707:
URL: https://github.com/apache/arrow-adbc/pull/707#discussion_r1204933000


##########
c/driver/postgresql/statement.cc:
##########
@@ -649,17 +649,27 @@ AdbcStatusCode PostgresStatement::ExecuteQuery(struct 
ArrowArrayStream* stream,
     return ADBC_STATUS_INVALID_STATE;
   }
 
-  // 1. Execute the query with LIMIT 0 to get the schema
+  // 1. Prepare the query to get the schema
   {
     // TODO: we should pipeline here and assume this will succeed
-    std::string schema_query = "SELECT * FROM (" + query_ + ") AS ignored 
LIMIT 0";
-    PGresult* result =
-        PQexecParams(connection_->conn(), query_.c_str(), /*nParams=*/0,
-                     /*paramTypes=*/nullptr, /*paramValues=*/nullptr,
-                     /*paramLengths=*/nullptr, /*paramFormats=*/nullptr, 
kPgBinaryFormat);
-    if (PQresultStatus(result) != PGRES_TUPLES_OK) {
-      SetError(error, "%s%s", "[libpq] Query was: ", schema_query.c_str());
-      SetError(error, "%s%s", "[libpq] Failed to execute query: could not 
infer schema: ",
+    PGresult* result = PQprepare(connection_->conn(), /*stmtName=*/"", 
query_.c_str(),
+                                 /*nParams=*/0, nullptr);
+    if (PQresultStatus(result) != PGRES_COMMAND_OK) {
+      SetError(error, "%s%s", "[libpq] Query was: ", query_.c_str());
+      SetError(error, "%s%s",
+               "[libpq] Failed to execute query: could not infer schema: 
failed to "
+               "prepare query: ",
+               PQerrorMessage(connection_->conn()));

Review Comment:
   How about unifying these `SetError()`s to one `SetError()`?
   It seems that the current `SetError()` implementation discards the previous 
error message. (`[libpq] Query was: ${query}` is discarded.)



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to