| From: | Eric Zhu <erkangzhu(at)gmail(dot)com> |
|---|---|
| To: | pgsql-general(at)lists(dot)postgresql(dot)org |
| Subject: | Calling a SQL function inside a C function |
| Date: | 2020-08-26 22:37:08 |
| Message-ID: | CAF0GwR2V_0dca3P7sq60-d4okgM_S36kYc9_=r795DhttHcp+Q@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
How do I call a function defined using CREATE FUNCTION in SQL inside a C
function in an extension? I feel this should be possible as the query
parser is able to resolve the function names and arguments in a raw string
query. I want to know if there is a standard way to look up for
user-defined functions in the backend.
For example, I have a function defined in SQL:
```
CREATE FUNCTION times_two(x integer)
RETURNS integer AS $$
SELECT x*2
$$ LANGUAGE SQL;
```
Now I wish to call `times_two()` in a C extension similar to:
```
// Look up for the user-defined function times_two()
// ...
// Use the function.
Datum ret = DirectFunctionCall(times_two, Int32GetDatum(13));
```
Best,
Eric
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2020-08-26 23:33:54 | Re: Database cluster binary compatibility accross CPU platforms |
| Previous Message | Aleš Zelený | 2020-08-26 22:19:47 | Database cluster binary compatibility accross CPU platforms |