red-4 / curious-moon

The Repository for the book, A Curious Moon, which you can purchase from https://bigmachine.io.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Function Error [PDF:301]

amarakov opened this issue · comments

My attempt to run the query on pg 301, after making a materialized view and a function, returns the following error:

ERROR:  could not read block 26 in file "base/16387/18490": Bad address
CONTEXT:  SQL function "low_time" statement 1

I've made sure that the first block of the query functions as expected

with lows_by_week as (
  select year, week,
  min(altitude) as altitude
  from flyby_altitudes
  group by year, week
)

The internet seems to think this has to do with something about function mutability, but since I'm pretty new to SQL that statement does not mean much to me. More importantly, I am not sure what I would change about the low_time() function declaration to avoid this error.

Any ideas?


For reference, the full block of code on this page is:

with lows_by_week as (
  select year, week,
  min(altitude) as altitude
  from flyby_altitudes
  group by year, week
), nadirs as (
  select low_time(altitude,year,week) as time_stamp,
  altitude
  from lows_by_week
)
select * from nadirs;