HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlModerate

How to pass a row as a parameter to a Postgres function?

Submitted by: @import:stackexchange-dba··
0
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:

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 ...

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.