Home >Database >Mysql Tutorial >How to Efficiently Extract Columns from Records Returned by a Database Function?
Columns Concatenated in Record Returned by Function
When joining a table with a function that returns multiple columns, it's essential to account for potential data concatenation issues. To address this challenge, let's explore different approaches for extracting individual columns from the returned record.
General Approach for Decomposing Rows
To decompose the rows returned by a function, use the following syntax:
SELECT * FROM function_name(arguments);
Postgres 9.3 and Newer: Using JOIN LATERAL to Decompose Results
For Postgres 9.3 or above, you can leverage JOIN LATERAL to decompose the results more cleanly:
SELECT ... FROM table_name a JOIN LATERAL function_name(a.accountid, '2014-08-12') f WHERE ...
Postgres 9.2 or Older: Decomposing Results Using a Subquery
In earlier Postgres versions, you can decompose the results using a subquery:
SELECT ... FROM ( SELECT a.*, function_name(a.accountid, '2014-08-12') AS rec FROM table_name a WHERE ... ) a
Best Practices for Decomposing Results
The above is the detailed content of How to Efficiently Extract Columns from Records Returned by a Database Function?. For more information, please follow other related articles on the PHP Chinese website!