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 9037477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:15:18+00:00 2026-06-16T09:15:18+00:00

I’m trying to fasten posgresql selection using a function by means of saying it’s

  • 0

I’m trying to fasten posgresql selection using a function by means of saying it’s immutable or stable, so I have a function

CREATE OR REPLACE FUNCTION get_data(uid uuid)
RETURNS integer AS $$
BEGIN
    RAISE NOTICE 'UUID %', $1;
-- DO SOME STUFF
    RETURN 0;

END;
$$ LANGUAGE plpgsql IMMUTABLE STRICT;

When I call it like:

SELECT get_data('3642e529-b098-4db4-b7e7-6bb62f8dcbba'::uuid)
  FROM table
 WHERE true LIMIT 100;

I have 100 results and only one notice raised

When I call it this way:

SELECT get_data(table.hash)
  FROM table
 WHERE 1 = 1 AND table.hash = '3642e529-b098-4db4-b7e7-6bb62f8dcbba' LIMIT 100;

I have 100 result and 100 notices raised

the condition (table.hash = ‘3642e529-b098-4db4-b7e7-6bb62f8dcbba’) added to make sure that the in param is the same

table.hash is uuid type

The questions is:
So how can force PG to some how cache the result of the function? ( if it’s possibe )
I want to have only one notice ( function call ) be raised in the second case…

  • 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-16T09:15:19+00:00Added an answer on June 16, 2026 at 9:15 am

    In your first example get_data('3642e529-b098-4db4-b7e7-6bb62f8dcbba'::uuid) is a constant, independent of table rows, so it is evaluated once.

    In the second example get_data(table.hash) is functionally depending on a column value, therefore it is evaluated once per row.

    If you want to evaluate the function once, it cannot depend on a value from a column (when more than one row is processed).


    After discussion in comments, here is an example how to call function only once per hash:

    SELECT *, get_data(x.hash) AS some_data_once_per_hash
    FROM    (
        SELECT hash, count(*) AS ct
        FROM   table
        WHERE  table.hash = '3642e529-b098-4db4-b7e7-6bb62f8dcbba'
        GROUP  BY 1
        ) x
    
    • 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
Basically, what I'm trying to create is a page of div tags, each has
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.