> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wherobots.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ST_Within

Tests whether geography `A` is fully within geography `B` using S2 spherical boolean operations. Returns true when every point of `A`'s interior lies in `B`'s interior. By OGC convention, `ST_Within(A, B)` is equivalent to `ST_Contains(B, A)`, and shares the same boundary semantics.

Boundary semantics on the sphere are inherited from S2's boolean operations and depend on each ring's vertex orientation: along an edge that is "owned" by `B`'s boundary the test returns true, and along the opposite edge it returns false. Do not rely on a specific result for points that lie exactly on `B`'s boundary; for predictable behavior, use a strict interior point or expand `B` slightly with `ST_Buffer` before testing.

<img src="https://mintcdn.com/wherobots/dMcCnpwodlRbDvhs/images/sql-functions/ST_Within_geography/ST_Within_geography_true.svg?fit=max&auto=format&n=dMcCnpwodlRbDvhs&q=85&s=76aede35a0e440d66a258c6cf2701d64" alt="ST_Within returning true" width="500" height="300" data-path="images/sql-functions/ST_Within_geography/ST_Within_geography_true.svg" />

<img src="https://mintcdn.com/wherobots/dMcCnpwodlRbDvhs/images/sql-functions/ST_Within_geography/ST_Within_geography_false.svg?fit=max&auto=format&n=dMcCnpwodlRbDvhs&q=85&s=2370ec8b1408d0bf150b0a97ef481701" alt="ST_Within returning false" width="500" height="300" data-path="images/sql-functions/ST_Within_geography/ST_Within_geography_false.svg" />

## Signatures

```sql theme={"system"}
ST_Within (A: Geography, B: Geography)
```

## Parameters

<ParamField body="A" type="Geography" required>
  The geography tested for being within B.
</ParamField>

<ParamField body="B" type="Geography" required>
  The containing geography.
</ParamField>

## Return type

<ResponseField type="Boolean">
  `true` if A is fully within B.
</ResponseField>

## Example

```sql theme={"system"}
SELECT ST_Within(
  ST_GeogFromWKT('POINT (0.5 0.5)', 4326),
  ST_GeogFromWKT('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))', 4326)
);
```

```
true
```
