Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

api.stay_view

Description

Stay listing web view

Table Definition
CREATE VIEW stay_view AS (
 SELECT s.id,
    s.name,
    m.name AS moorage,
    m.id AS moorage_id,
    (s.departed - s.arrived) AS duration,
    sa.description AS stayed_at,
    sa.stay_code AS stayed_at_id,
    s.arrived,
    "from".id AS arrived_log_id,
    "from"._to_moorage_id AS arrived_from_moorage_id,
    "from"._to AS arrived_from_moorage_name,
    s.departed,
    "to".id AS departed_log_id,
    "to"._from_moorage_id AS departed_to_moorage_id,
    "to"._from AS departed_to_moorage_name,
    s.notes,
        CASE
            WHEN (jsonb_array_length((s.user_data -> 'images'::text)) > 0) THEN true
            ELSE false
        END AS has_images,
    (s.user_data -> 'images'::text) AS images
   FROM ((((api.stays s
     JOIN api.moorages m ON ((s.moorage_id = m.id)))
     JOIN api.stays_at sa ON ((s.stay_code = sa.stay_code)))
     LEFT JOIN api.logbook "from" ON ((("from"._from_time = s.departed) AND ("from"._to_moorage_id IS NOT NULL))))
     LEFT JOIN api.logbook "to" ON (("to"._to_time = s.arrived)))
  WHERE ((s.departed IS NOT NULL) AND (s.name IS NOT NULL))
  ORDER BY s.arrived DESC
)

Columns

NameTypeDefaultNullable
arrivedtimestamp with time zonetrue
arrived_from_moorage_idintegertrue
arrived_from_moorage_nametexttrue
arrived_log_idintegertrue
departedtimestamp with time zonetrue
departed_log_idintegertrue
departed_to_moorage_idintegertrue
departed_to_moorage_nametexttrue
durationintervaltrue
has_imagesbooleantrue
idintegertrue
imagesjsonbtrue
mooragetexttrue
moorage_idintegertrue
nametexttrue
notestexttrue
stayed_attexttrue
stayed_at_idintegertrue

Referenced Tables

NameColumnsCommentType
api.stays15The stays table records time spent at moorages. Each stay links a moorage with arrival/departure timestamps. RLS policies filter by vessel_id.BASE TABLE
api.moorages14The moorages table stores locations where vessels can stay (marinas, anchorages, etc.). Each moorage has geographic coordinates and metadata.BASE TABLE
api.stays_at2Stay TypeBASE TABLE
api.logbook43The logbook table stores vessel navigation entries with timestamps, locations, and trip metrics. RLS policies filter by vessel_id automatically.
These indexes optimize different query patterns while minimizing storage.
BASE TABLE

Relations

erDiagram


"api.stay_view" {
  timestamp_with_time_zone arrived ""
  integer arrived_from_moorage_id ""
  text arrived_from_moorage_name ""
  integer arrived_log_id ""
  timestamp_with_time_zone departed ""
  integer departed_log_id ""
  integer departed_to_moorage_id ""
  text departed_to_moorage_name ""
  interval duration ""
  boolean has_images ""
  integer id ""
  jsonb images ""
  text moorage ""
  integer moorage_id ""
  text name ""
  text notes ""
  text stayed_at ""
  integer stayed_at_id ""
}

Generated by tbls