Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8857879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:41:49+00:00 2026-06-14T14:41:49+00:00

I am trying to call a function which is declared in PostgreSQL with PL/pgSQL.

  • 0

I am trying to call a function which is declared in PostgreSQL with PL/pgSQL. For that I write the code below. My function is working but after that I am taking a “PGRES_FATAL_ERROR”. Also when I changed “select removestopwords()” with an sql query like “DELETE * FROM TABLE1” it’s working successfully.

I am considering, that error can cause some big problem in future even if now working. How can I call a PL/pgSQL function without taking error?

void removeStopWordsDB(PGconn* conn) {

PGresult *res = PQexec(conn, "select removestopwords()");

if (PQresultStatus(res) != PGRES_COMMAND_OK) {
    printf("removestopwords failed");
    cout<<PQresultStatus(res);
    PQclear(res);
    exit_nicely(conn);
}

printf("removestopwords - OK\n");

PQclear(res);

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:41:50+00:00Added an answer on June 14, 2026 at 2:41 pm

    If you get PGRES_FATAL_ERROR from PQresultStatus you should use PQresultErrorField to get all the error data from the result set to provide a useful error message. This will allow you to determine what the actual error is here (quite likely an error being sent over from the server).

    Consider creating a class to hold PostgreSQL error details that can be constructed from q PQresult pointer, e.g.:

    PgError(const PGresult *rs)
    {
      severity = GetErrorField(rs, PG_DIAG_SEVERITY);
      sqlstate = GetErrorField(rs, PG_DIAG_SQLSTATE);
      primary = GetErrorField(rs, PG_DIAG_MESSAGE_PRIMARY);
      // ...
    }
    static std::string GetErrorField(const PGresult *rs, int fieldCode)
    {
      const char *message = PQresultErrorField(rs, fieldCode);
      if (message == NULL) return "";
      return std::string(message);
    }
    

    Then you can, for example, encapsulate dumping out the error to a stream in this object to provide details just like psql and friends do (although strictly speaking, you’d need the input SQL as well for all of that)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a trigger function in PostgreSQL 8.2 that will dynamically
trying to make a page which will recursively call a function until a limit
I'm currently trying to register a JS function call from a .NET page which
I have the following C++ function definition, which I am trying to call through
I am trying to call c# function from javascript the code i have tried
I am trying to call a function, but am running into some struggles with
I have piece of function which I am trying to call at two different
I am trying to write a Java function which has List object as output
I'm currently trying to make a set of conversion functions which, through one call,
I'm trying to call a function present in one class from another class by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.