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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:06:02+00:00 2026-05-23T18:06:02+00:00

I am running into a wierd issue with the execution (or non-execution) of certain

  • 0

I am running into a wierd issue with the execution (or non-execution) of certain queries within postgresql RULES. This is a companion (but different) question to Postgresql subquery execution within ON UPDATE rule (maybe bug in postgresql?) – but as it turns out, there is a related issue of certain queries not executing at all within postgresql RULEs, versus just the issue of query execution order.

Consider the following code block:

DROP TABLE foo_table;
DROP TABLE bar_table;

--------------

CREATE TABLE foo_table (c1 text, c2 int);
CREATE TABLE bar_table (c1 text, c2 int);

--------------

CREATE OR REPLACE FUNCTION debug_immutable(anyelement) RETURNS integer AS $$

pg_raise('notice', 'debug(): ' . json_encode($args[0]));

return rand(1, 10000);

$$ LANGUAGE PLPHP IMMUTABLE;

CREATE OR REPLACE FUNCTION debug_volatile(anyelement) RETURNS integer AS $$

pg_raise('notice', 'debug(): ' . json_encode($args[0]));

return rand(1, 10000);

$$ LANGUAGE PLPHP VOLATILE;

-------------

CREATE OR REPLACE RULE foo_update_rule AS ON UPDATE TO foo_table DO INSTEAD
(

SELECT debug_immutable('debug_immutable call 1'::text); -- Query #1

SELECT debug_volatile('debug_volatile call 1'::text);   -- Query #2

INSERT INTO foo_table (c1, c2) values ('foo', 123456);  -- Query #3

INSERT INTO bar_table (c1, c2) values ('bar', 123456);  -- Query #4

SELECT debug_immutable('debug_immutable call 2'::text); -- Query #5

SELECT debug_volatile('debug_volatile call 2'::text);   -- Query #6
);

-----------------------------------------------

UPDATE foo_table SET c1 = NULL where c1 = 'aaa';

SELECT * FROM foo_table;

SELECT * FROM bar_table;

The output only displays the following:

NOTICE:  plphp: debug(): "debug_immutable call 1"
NOTICE:  plphp: debug(): "debug_immutable call 2"
Total query runtime: 46 ms.
0 rows retrieved.

And both foo_table and bar_table shows to be empty after the code block is executed:

# select * from foo_table;
 c1 | c2 
----+----
(0 rows)

# select * from bar_table;
 c1 | c2 
----+----
(0 rows)

The output implies that only queries #1 and #5 are executed, and queries #2, 3, 4 and 6 are never executed. Why is this? How can the above code block be changed so that queries #2, 3, 4 and 6 are executed?

  • 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-05-23T18:06:03+00:00Added an answer on May 23, 2026 at 6:06 pm

    The immutable functions are evaluated at the planning stage, before the query is executed. The volatile ones are evaluated on a per need basis. You’ve zero rows returned, so they’re never called.

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

Sidebar

Related Questions

I'm running into a weird issue with Entity Framework in .NET 3.5 SP1 within
So I'm running into this weird issue. When I'm developing locally, and I run
I have a Custom Listview but i'm running into a weird issue when I
I am running into this weird issue where I am iterating over a list
I'm trying to style a menu, but I keep running into this weird margin
I'm trying to setup Gitolite but I'm running into a weird issue: When I
I'm running into a weird issue that I'm struggling to figure out what's causing
Running into a problem where on certain servers we get an error that the
Been running into this problem lately... When debugging an app in VS.Net 2005, breakpoints
I'm running into an issue where I have a FileUpload control in an UpdatePanel.

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.