Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create bolder warnings for people to not use returns table and returns setof record and out/inout parameters #2338

Open
benjie opened this issue Jan 27, 2025 · 3 comments

Comments

@benjie
Copy link
Member

benjie commented Jan 27, 2025

They work, but they're hard to work with; see: https://postgraphile.org/postgraphile/next/customization-overview/#adding-a-field-to-a-function-derived-type

@benjie
Copy link
Member Author

benjie commented Jan 27, 2025

See also this comment from me on how anonymous types are handled and why you should use setof:

#2331 (comment)

There's also another example in a follow-up comment in that same thread.

@benjie
Copy link
Member Author

benjie commented Feb 3, 2025

Noted by @machineghost in #2331 (comment):

As a side note, returns table is extremely popular in Stack Overflow PostgreSQL function examples, so anyone learning from SO (ie. a very healthy percentage of Postgraphile users) will be copying function code with returns table. Perhaps this "advice" should be a big/bold/visible warning.

It may also be worth warning about this in PostGraphile's console output, maybe. Something like:

Warning: The function schema_name.function_name uses {returns table | out/inout arguments} which means that the type it returns is "anonymous". Anonymous types are very hard to augment in PostGraphile, we recommend that you instead return a new (or existing) named type - the body of your function does not need to change, only the return type - for instructions, see https://err.red/pnt

@machineghost
Copy link
Contributor

I like the idea. Some people might miss it in all the console spam, but it will help many others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🌳 Triage
Development

No branches or pull requests

2 participants