snippetsqlModerate
How to pass a row as a parameter to a Postgres function?
Viewed 0 times
postgrespassfunctionhowrowparameter
Problem
I have a function build_details(), which takes as one of its parameters, a single row/record from another table.
This is what I want to do, but it doesn't work:
I want to take a single row from my_table and pass it to the function so that I can make it run. How do I call the function from the terminal with a record from my_table?
This is what I want to do, but it doesn't work:
SELECT build_details(
SELECT * FROM my_table LIMIT 1,
1000,
TRUE)I want to take a single row from my_table and pass it to the function so that I can make it run. How do I call the function from the terminal with a record from my_table?
Solution
It's much simpler that that. While one would expect it to be ...
... the actual syntax is:
SELECT build_details(my_table.*, 1000, TRUE) FROM my_table LIMIT 1;... the actual syntax is:
SELECT build_details(my_table, 1000, TRUE) FROM my_table LIMIT 1;Code Snippets
SELECT build_details(my_table.*, 1000, TRUE) FROM my_table LIMIT 1;SELECT build_details(my_table, 1000, TRUE) FROM my_table LIMIT 1;Context
StackExchange Database Administrators Q#147273, answer score: 12
Revisions (0)
No revisions yet.