vendredi 29 mars 2019

How to use perform a select on table under schema in postgres Database?

i'm trying to perform a select operation on postgres DB table and i'm getting below error:

[etb@centos etbtest]$ ./a.out

Opened database successfully: ETBDB ERROR: relation "etb_reference.etb_member" does not exist LINE 1: SELECT * FROM etb_reference.ETB_MEMBER

how do we refer the schema name in libpq++ exec function?

i tried escaping the schema name with other escape options like ",',\ etc but it didn't help.

my code :

   try {
      connection C("dbname = ETBDB user = etbadm password = etbtest \
      hostaddr = 127.0.0.1 port = 5432");
      if (C.is_open()) {
         cout << "Opened database successfully: " << C.dbname() << endl;
      } else {
         cout << "Can't open database" << endl;
         return 1;
      }

       work wrk(C);

   result res = wrk.exec("SELECT * FROM etb_reference.ETB_MEMBER");

   for (
      pqxx::result::const_iterator row = res.begin();
      row != res.end();
      ++row)
    {

     std::cout
        << row["MEMBER_ID"].as<int>() << "\t"
        << row["SYS_CRE_DATE"].as<std::string>() << "\t"
        << row["SYS_UPD_DATE"].as<std::string>() << "\t"
        << row["MEMBER_CS"].as<std::string>() << "\t"
        << row["MEMBER_TD"].as<std::string>() << "\t"
        << row["MEMBER_ASD"].as<std::string>() << "\t"
        << row["MEMBER_ITM"].as<std::string>() << "\t"
        << std::endl;

    }
C.disconnect ();
 return 0;

   } catch (const std::exception &e) {
      cerr << e.what() << std::endl;
      return 1;
   }
}

Aucun commentaire:

Enregistrer un commentaire