How to determine if a function exists
От | lmanorders |
---|---|
Тема | How to determine if a function exists |
Дата | |
Msg-id | 8310E014117E4AF990DC0A1745A7CB4B@LynnPC обсуждение исходный текст |
Ответы |
Re: How to determine if a function exists
|
Список | pgsql-novice |
I'm attempting to determine if a stored procedure exists. If it doesn't, then I want to create it. I'm developing in C++ using the libpq interface. I found the following suggestion in the docs to determine if a function exists or not. I tried creating what I think is an identical query in pgAdmin and it seems to work ok. Can anyone tell me why the following always returns PGRES_TUPLE_OK, whether the function exists or not?
strcpy(command, "SELECT * FROM pg_proc WHERE proname = 'getdetailamtsacct'");
pqRes = PQexec(conn, command);
if (PQresultStatus(pqRes) != PGRES_TUPLES_OK)
{
// translate the status code into a string
pqExSt = PQresultStatus(pqRes);
strcpy(result, PQresStatus(pqExSt));
pqRes = PQexec(conn, command);
if (PQresultStatus(pqRes) != PGRES_TUPLES_OK)
{
// translate the status code into a string
pqExSt = PQresultStatus(pqRes);
strcpy(result, PQresStatus(pqExSt));
// display the status message
...
exist = false; // table doesn't exist
}
...
exist = false; // table doesn't exist
}
if (!exist)
{
// create the function (stored procedure)
}
Is there a better way to determine if a function already exists?
Thanks, Lynn
В списке pgsql-novice по дате отправления: