Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9274957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:28:32+00:00 2026-06-18T16:28:32+00:00

I’m trying to call a stored procedure passing parameters in a left outer join

  • 0

I’m trying to call a stored procedure passing parameters in a left outer join like this:

select i.name,sp.*
from items i
left join compute_prices(i.id,current_date) as sp(price numeric(15,2), 
          discount numeric(5,2), taxes numeric(5,2)) on 1=1
where i.type = 404;

compute_prices() returns a setof record.
This is the message postgres shows:

ERROR: invalid reference to FROM-clause entry for table “i”

…left join compute_prices(i.id,current_date)…

HINT: There is an entry for table “i”, but it cannot be referenced
from this part of the query.

This kind of query works in Firebird. Is there a way I could make it work by just using a query? I don’t want to create another stored procedure that cycles through items and makes separate calls to compute_prices().

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:28:33+00:00Added an answer on June 18, 2026 at 4:28 pm

    Generally, you can expand well known row types (a.k.a. record type, complex type, composite type) with the simple syntax @Daniel supplied:

    SELECT i.name, (compute_prices(i.id, current_date)).*
    FROM   items i
    WHERE  i.type = 404;
    

    However, if your description is accurate …

    The compute_prices sp returns a setof record.

    … we are dealing with anonymous records. Postgres does not know how to expand anonymous records and throws an EXCEPTION in despair:

    ERROR:  a column definition list is required for functions returning "record"
    

    PostgreSQL 9.3

    There is a solution for that in Postgres 9.3. LATERAL, as mentioned by @a_horse in the comments:

    SELECT i.name, sp.*
    FROM   items i
    LEFT   JOIN LATERAL compute_prices(i.id,current_date) AS sp (
                           price    numeric(15,2)
                          ,discount numeric(5,2)
                          ,taxes    numeric(5,2)
                          ) ON TRUE
    WHERE i.type = 404;
    

    Details in the manual.

    PostgreSQL 9.2 and earlier

    Things get hairy. Here’s a workaround: write a wrapper function that converts your anonymous records into a well known type:

    CREATE OR REPLACE FUNCTION compute_prices_wrapper(int, date)
      RETURNS TABLE (
                price    numeric(15,2)
               ,discount numeric(5,2)
               ,taxes    numeric(5,2)
              ) AS
    $func$
        SELECT * FROM compute_prices($1, $2)
        AS t(price    numeric(15,2)
            ,discount numeric(5,2)
            ,taxes    numeric(5,2));
    $func$ LANGUAGE sql;
    

    Then you can use the simple solution by @Daniel and just drop in the wrapper function:

    SELECT i.name, (compute_prices_wrapper(i.id, current_date)).*
    FROM   items i
    WHERE  i.type = 404;
    

    PostgreSQL 8.3 and earlier

    PostgreSQL 8.3 has just reached EOL and is unsupported as of now (Feb. 2013).
    So you’d better upgrade if at all possible. But if you can’t:

    CREATE OR REPLACE FUNCTION compute_prices_wrapper(int, date
               ,OUT price    numeric(15,2)
               ,OUT discount numeric(5,2)
               ,OUT taxes    numeric(5,2))
      RETURNS SETOF record AS
    $func$
        SELECT * FROM compute_prices($1, $2)
        AS t(price    numeric(15,2)
            ,discount numeric(5,2)
            ,taxes    numeric(5,2));
    $func$ LANGUAGE sql;
    

    Works in later versions, too.

    The proper solution would be to fix your function compute_prices() to return a well know type to begin with. Functions returning SETOF record are generally a PITA. I only poke those with a five-meter-pole.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a bunch of posts stored in text files formatted in yaml/textile (from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.