On Feb 4, 2025, at 12:19, kevin <
kbra...@pwhome.com> wrote:
> Hi,
Hello, and apologies for the delayed reply.
> I was looking for a way to test what a function returns and found ... function_returns(). 🙂
>
> Q1: Given that function_returns() has the function args, why do we also have has_function()?
Some people just want to check for the function without regard to its return value. Also I think `has_function()` might pre-date `function_returns()`.
> I don't know what the best syntax might be, but the point is to verify there are 5 columns for the record and what their types are. Thoughts?
Hrm, I don’t think you can specify the type of the record unless it’s pre-defined as a type (or table). So if you declared a composite type[1]:
```sql
CREATE TYPE count_coll AS (
download_id INT,
client_name VARCHAR,
source VARCHAR,
doc_type VARCHAR,
cnt INT
);
```
Then you can use has_column[2] to test each of the columns of the composite type. Then you could define the function as:
```sql
CREATE OR REPLACE FUNCTION find_workflow_counts (
...
) RETURNS count_coll;
```
And then test for that return value.
But also you might want to add some functional tests that execute the function and compare the return value to an expected value. Use row_eq[3] for that.
HTH,
David
[1]:
https://www.postgresql.org/docs/current/rowtypes.html
[2]:
https://pgtap.org/documentation.html#has_column
[3]:
https://pgtap.org/documentation.html#row_eq