Question

I'm writing a library that wraps libpq in C. When I execute a query like DROP SCHEMA IF EXISTS bob, and bob doesn't exist, libpq outputs

"NOTICE:  schema "bob" does not exist, skipping"

into my terminal, but then succeeds. Similarly, if I create a table with id serial primary key it prints a notice that it auto-generated a sequence.

How do I stop it printing this into the terminal? I have functions in my library to obtain such information, if the user needs it, but it should not just output into the terminal like this.

I didn't see anything in the documentation for PQexecParams(), or PQconnectdb() etc.

Was it helpful?

Solution

See libpq - notice processing in the manual. You need to supply a notice processor to replace the default one.

The default notice processor is simply:

static void
defaultNoticeProcessor(void *arg, const char *message)
{
    fprintf(stderr, "%s", message);
}

OTHER TIPS

One option is to change it's stdout (and/or stderr).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top