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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:31:37+00:00 2026-06-01T15:31:37+00:00

I think I’m losing it, can anyone explain why am I experiencing the following:

  • 0

I think I’m losing it, can anyone explain why am I experiencing the following:
Here is my query:

    update financials.operator_summary_daily set
        osm_fos_id = fos_id
    from financials.operator_summary_daily daily
    join (
        select 
            osm_id,
            fos_id
        from financials.operator_summary_daily daily
        join financials.operator_settlement_monthly on daily.osm_opt_id = fos_opt_id and date_trunc('month', daily.osm_timestamp)::timestamp = date_trunc('month', fos_timestamp)::timestamp --and daily.osm_fos_id is null
    ) as result on result.osm_id = daily.osm_id

inner query returns 1963 records, but the update is executed on the entire table of financials.operator_summary_daily and updates all 39K records.

What am I missing here?

Tables:

CREATE TABLE financials.operator_summary_daily
(
  osm_id bigint NOT NULL DEFAULT nextval('financials.operator_summary_monthly_osm_id_seq'::regclass),
  osm_timestamp timestamp without time zone NOT NULL,
  osm_opt_id bigint NOT NULL,
  osm_gam_id bigint NOT NULL,
  osm_cur_id bigint NOT NULL,
  osm_ctt_id bigint NOT NULL,
  osm_turnover double precision NOT NULL,
  osm_revenue double precision NOT NULL,
  osm_timestamp_created timestamp without time zone NOT NULL DEFAULT now(),
  osm_timestamp_updated timestamp without time zone NOT NULL DEFAULT ('now'::text)::date,
  osm_fos_id bigint
);


CREATE TABLE financials.operator_settlement_monthly
(
  fos_id bigserial NOT NULL,
  fos_timestamp timestamp without time zone NOT NULL, -- Monthly timestamp
  fos_opt_id bigint NOT NULL,
  fos_royalties double precision NOT NULL,
  fos_carry_over double precision NOT NULL,
  fos_other_adjustments double precision NOT NULL,
  fos_due double precision NOT NULL,
  fos_collectable double precision NOT NULL,
  fos_balance double precision NOT NULL,
  fos_collected double precision NOT NULL,
  fos_baddebt double precision NOT NULL,
  fos_carryforward double precision NOT NULL,
  fos_ses_id bigint NOT NULL,
  fos_timestamp_created timestamp without time zone NOT NULL DEFAULT now(),
  fos_datetime_updated timestamp without time zone NOT NULL DEFAULT now(),
  fos_prq_id bigint
);

EDIT:
Thank you for your quick answers, however there shouldn’t be a need for a where, the join condition is not LEFT, it’s inclusive and should render only the matched rows for the update. Therefore, only 1963 records out of the 37K (those meeting the join criteria) should be updated. Am I wrong?

ANSWER:
The correct script:

    UPDATE financials.operator_summary_daily d
    SET    osm_fos_id = m.fos_id
    FROM   financials.operator_settlement_monthly m
    WHERE  
        m.fos_opt_id = d.osm_opt_id
        AND    date_trunc('month', d.osm_timestamp) = date_trunc('month', m.fos_timestamp)
        AND d.osm_fos_id is null; 

Thank you @ErwinBrandstetter.
Apparently, I’ve been using a wrong assumption for the JOIN, my background is MS-SQL and it works differently there.
From looking at the end end solution, the JOIN was completely dropped and exchanged with a direct call to the secondary table, something you cannot do in T-SQL.

BTW, the following does not work and it does contain a where clause as other comments suggested. I’m still puzzled as to how pgsql works with regards to JOIN when Updating records.

    update financials.operator_summary_daily set
        osm_fos_id = fos_id
    from financials.operator_summary_daily daily
    join (
        select 
            osm_id,
            fos_id
        from financials.operator_summary_daily daily
        join financials.operator_settlement_monthly on daily.osm_opt_id = fos_opt_id and date_trunc('month', daily.osm_timestamp)::timestamp = date_trunc('month', fos_timestamp)::timestamp 
    ) as result on result.osm_id = daily.osm_id
    where
        daily.osm_id = result.osm_id
        and daily.osm_fos_id is null;
  • The complicated join is a result of me trying to ensure the inner query returns only a subset of the whole table for “debugging” purposes.

Thanks again!

  • 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-01T15:31:39+00:00Added an answer on June 1, 2026 at 3:31 pm

    There is no WHERE condition to your UPDATE.

    This statement will update all rows.

    Your statement might work like this (much simplified):

    UPDATE financials.operator_summary_daily d
    SET    osm_fos_id = m.fos_id
    FROM   financials.operator_settlement_monthly m
    WHERE  m.fos_opt_id = d.osm_opt_id
    AND    date_trunc('month', d.osm_timestamp) = date_trunc('month', m.fos_timestamp)
    -- AND daily.osm_fos_id is null -- ?? Why is this here / commented out?
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Think about the following: Your ISP offers you a dynamic ip-address (for example 123.123.123.123).
I think I'm burnt out, and that's why I can't see an obvious mistake.
i think my whole questions is inside title bar =] but i'll explain little
Think of the following code: static int Main() { byte[] data = File.ReadAllBytes(anyfile); SomeMethod(data);
Think of the following services on one box: SOCKS proxy HTTP proxy SSH service
Think 2 entities OneToOne mapped. Person and Car. A Person can have a Car.
I think I'm missing something basic here. Why is the third IF condition true?
I think I'm missing something basic here. Any explanation or pointers to previously asked
Think of a equations system like the following: a* = b + f +
I think most people here understand the importance of fully automated builds. The problem

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.