Company
Date Published
Author
Bryn Llewellyn
Word count
1392
Language
English
Hacker News points
None

Summary

Implementing PostgreSQL user-defined table functions in YugabyteDB allows for creating parameterized views, encapsulating the choice between different source tables while ensuring static SQL proof against SQL injection. The function can be defined using either `return next`, to return the next explicitly computed row, or `return query`, to return the entire result set of a select statement. User-defined table functions can be implemented in various languages, including PostgreSQL's `plpgsql` and `language sql`. The `return next` language is the most general, allowing for computing sets of values for each returned row explicitly, but it has limitations due to the fact that the entire result set is materialized before returning from the function. This behavior contrasts with Oracle database's pipelined table functions, which deliver results on demand. PostgreSQL table functions are most useful when delivering small, bounded result sets, making them suitable for various use cases such as parameterized views and encapsulating source tables while ensuring static SQL proof against SQL injection.