Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

chore: format all sql code blocks in mdx

Qiao Hanf86ea9f5ac14
diff --git a/apps/docs/pages/guides/cli/local-development.mdx b/apps/docs/pages/guides/cli/local-development.mdx
index 1c8f21a9b05..0514e6b108a 100644
--- a/apps/docs/pages/guides/cli/local-development.mdx
+++ b/apps/docs/pages/guides/cli/local-development.mdx
@@ -178,9 +178,9 @@ This creates a new migration named `supabase/migrations/<timestamp>_create_emplo
Use the seed script in `supabase/seed.sql` (created with [`supabase init`](/docs/reference/cli/usage#supabase-init)) to add sample data to the table.
```sql
- -- in supabase/seed.sql
-insert into
- public.employees (name)
+-- in supabase/seed.sql
+insert into public.employees
+ (name)
values
('Erlich Bachman'),
('Richard Hendricks'),
@@ -200,9 +200,9 @@ You should now see the contents of `employees` in Studio.
Use the [`reset`](/docs/reference/cli/usage#supabase-db-reset) command to revert any changes to the local database.
```sql
- -- run on local database to make a change
-alter table
- employees add department text default 'Hooli';
+-- run on local database to make a change
+alter table employees
+add department text default 'Hooli';
```
Run the following command to reset the local database:
diff --git a/apps/docs/pages/guides/database/api.mdx b/apps/docs/pages/guides/database/api.mdx
index fc8f86a18ae..04e5ecb97db 100644
--- a/apps/docs/pages/guides/database/api.mdx
+++ b/apps/docs/pages/guides/database/api.mdx
@@ -390,7 +390,7 @@ This ensures that any `delete()` or `update()` would fail if there are no accomp
To confirm that safeupdate is enabled for queries going through the API of your project, the following query could be run:
```sql
-select usename,useconfig from pg_shadow where usename = 'authenticator' ;
+select usename, useconfig from pg_shadow where usename = 'authenticator';
```
The expected value for `useconfig` should be:
diff --git a/apps/docs/pages/guides/database/arrays.mdx b/apps/docs/pages/guides/database/arrays.mdx
index 17595464aee..e59be4a6d4b 100644
--- a/apps/docs/pages/guides/database/arrays.mdx
+++ b/apps/docs/pages/guides/database/arrays.mdx
@@ -30,7 +30,10 @@ Create a test table with a text array (an array of strings):
<TabPanel id="sql" label="SQL">
```sql
-CREATE TABLE arraytest (id integer NOT NULL, textarray text ARRAY);
+create table arraytest (
+ id integer not null,
+ textarray text array
+);
```
</TabPanel>
@@ -95,7 +98,7 @@ You should see:
<TabPanel id="sql" label="SQL">
```sql
-SELECT * FROM arraytest;
+select * from arraytest;
```
You should see:
diff --git a/apps/docs/pages/guides/database/extensions/pg_stat_monitor.mdx b/apps/docs/pages/guides/database/extensions/pg_stat_monitor.mdx
index 4c1363b83b9..232bbb116e0 100644
--- a/apps/docs/pages/guides/database/extensions/pg_stat_monitor.mdx
+++ b/apps/docs/pages/guides/database/extensions/pg_stat_monitor.mdx
@@ -76,6 +76,7 @@ The following table shows a subset of available columns:
A full list of statistics is available in the [pg_stat_monitor docs](https://docs.percona.com/pg-stat-monitor/reference.html#postgresql-15).
## Functions
+
- [`pg_stat_monitor_reset()`](https://docs.percona.com/pg-stat-monitor/functions.html): Resets the statistics tracked by the `pg_stat_monitor` view and deletes all previous data.
- [`pg_stat_monitor_version()`](https://docs.percona.com/pg-stat-monitor/functions.html): Displays the version of the `pg_stat_monitor` extension.
diff --git a/apps/docs/pages/guides/database/extensions/pgcron.mdx b/apps/docs/pages/guides/database/extensions/pgcron.mdx
index 1062db0fd32..8b4b5016c4d 100644
--- a/apps/docs/pages/guides/database/extensions/pgcron.mdx
+++ b/apps/docs/pages/guides/database/extensions/pgcron.mdx
@@ -84,7 +84,7 @@ select cron.schedule (
Vacuum every day at 3:00am (GMT)
```sql
-SELECT cron.schedule('nightly-vacuum', '0 3 * * *', 'VACUUM');
+select cron.schedule('nightly-vacuum', '0 3 * * *', 'VACUUM');
```
### Invoke Supabase Edge Function every minute
@@ -112,7 +112,7 @@ select
Unschedules a job called `'nightly-vacuum'`
```sql
-SELECT cron.unschedule('nightly-vacuum');
+select cron.unschedule('nightly-vacuum');
```
## Resources
diff --git a/apps/docs/pages/guides/database/extensions/pgnet.mdx b/apps/docs/pages/guides/database/extensions/pgnet.mdx
index 3246fb4f5df..5a93b7a48b5 100644
--- a/apps/docs/pages/guides/database/extensions/pgnet.mdx
+++ b/apps/docs/pages/guides/database/extensions/pgnet.mdx
@@ -16,7 +16,6 @@ The pg_net API is in alpha. Functions signatures may change.
It differs from the `http` extension in that it is asynchronous by default. This makes it useful in blocking functions (like triggers).
-
## Enable the extension
<Tabs
diff --git a/apps/docs/pages/guides/database/extensions/pgroonga.mdx b/apps/docs/pages/guides/database/extensions/pgroonga.mdx
index 098107a580c..669c5d7829b 100644
--- a/apps/docs/pages/guides/database/extensions/pgroonga.mdx
+++ b/apps/docs/pages/guides/database/extensions/pgroonga.mdx
@@ -8,7 +8,6 @@ export const meta = {
`PGroonga` is a PostgreSQL extension adding a full text search indexing method based on [Groonga](https://groonga.org). While native PostgreSQL supports full text indexing, it is limited to alphabet and digit based languages. `PGroonga` offers a wider range of character support making it viable for a superset of languages supported by PostgreSQL including Japanese, Chinese, etc.
-
## Enable the extension
<Tabs
diff --git a/apps/docs/pages/guides/database/extensions/pgvector.mdx b/apps/docs/pages/guides/database/extensions/pgvector.mdx
index 42118b9197f..ca4ab986a90 100644
--- a/apps/docs/pages/guides/database/extensions/pgvector.mdx
+++ b/apps/docs/pages/guides/database/extensions/pgvector.mdx
@@ -60,13 +60,12 @@ To disable an extension, call `drop extension`.
### Create a table to store vectors
```sql
-create table
- posts (
- id serial primary key,
- title text not null,
- body text not null,
- embedding vector (1536)
- );
+create table posts (
+ id serial primary key,
+ title text not null,
+ body text not null,
+ embedding vector(1536)
+);
```
### Storing a vector / embedding
diff --git a/apps/docs/pages/guides/database/extensions/plv8.mdx b/apps/docs/pages/guides/database/extensions/plv8.mdx
index fdb827f85da..bac280e8d78 100644
--- a/apps/docs/pages/guides/database/extensions/plv8.mdx
+++ b/apps/docs/pages/guides/database/extensions/plv8.mdx
@@ -15,7 +15,6 @@ While Postgres natively runs SQL, it can also run other "procedural languages".
It can be used for database functions, triggers, queries and more.
-
## Enable the extension
<Tabs
diff --git a/apps/docs/pages/guides/database/extensions/postgis.mdx b/apps/docs/pages/guides/database/extensions/postgis.mdx
index 9e9a65098ad..89c2b259339 100644
--- a/apps/docs/pages/guides/database/extensions/postgis.mdx
+++ b/apps/docs/pages/guides/database/extensions/postgis.mdx
@@ -91,7 +91,7 @@ You can insert geographical data through SQL or through our API.
```sql
insert into public.restaurants
-(name, location)
+ (name, location)
values
('Supa Burger', st_point(-73.946823, 40.807416)),
('Supa Pizza', st_point(-73.94581, 40.807475)),
diff --git a/apps/docs/pages/guides/database/extensions/wrappers.mdx b/apps/docs/pages/guides/database/extensions/wrappers.mdx
index 943b1dd6391..c0ba008b275 100644
--- a/apps/docs/pages/guides/database/extensions/wrappers.mdx
+++ b/apps/docs/pages/guides/database/extensions/wrappers.mdx
@@ -6,7 +6,7 @@ export const meta = {
description: '3rd party integrations for PostgreSQL ',
}
-[supabase/wrappers](https://supabase.github.io/wrappers/) is a PostgreSQL extension that provides integrations with external sources so you can interact with third-party data using SQL.
+[supabase/wrappers](https://supabase.github.io/wrappers/) is a PostgreSQL extension that provides integrations with external sources so you can interact with third-party data using SQL.
For example, the [Stripe wrapper](https://supabase.github.io/wrappers/stripe/) connects to [Stripe's API](https://stripe.com/docs/api) and exposes each endpoint as a SQL table.
diff --git a/apps/docs/pages/guides/database/full-text-search.mdx b/apps/docs/pages/guides/database/full-text-search.mdx
index 6e2ec9ca087..f3d98ff302a 100644
--- a/apps/docs/pages/guides/database/full-text-search.mdx
+++ b/apps/docs/pages/guides/database/full-text-search.mdx
@@ -49,13 +49,26 @@ create table books (
description text
);
-insert into books (title, author, description)
+insert into books
+ (title, author, description)
values
- ('The Poky Little Puppy','Janette Sebring Lowrey','Puppy is slower than other, bigger animals.'),
- ('The Tale of Peter Rabbit','Beatrix Potter','Rabbit eats some vegetables.'),
- ('Tootle','Gertrude Crampton','Little toy train has big dreams.'),
- ('Green Eggs and Ham','Dr. Seuss','Sam has changing food preferences and eats unusually colored food.'),
- ('Harry Potter and the Goblet of Fire','J.K. Rowling','Fourth year of school starts, big drama ensues.');
+ (
+ 'The Poky Little Puppy',
+ 'Janette Sebring Lowrey',
+ 'Puppy is slower than other, bigger animals.'
+ ),
+ ('The Tale of Peter Rabbit', 'Beatrix Potter', 'Rabbit eats some vegetables.'),
+ ('Tootle', 'Gertrude Crampton', 'Little toy train has big dreams.'),
+ (
+ 'Green Eggs and Ham',
+ 'Dr. Seuss',
+ 'Sam has changing food preferences and eats unusually colored food.'
+ ),
+ (
+ 'Harry Potter and the Goblet of Fire',
+ 'J.K. Rowling',
+ 'Fourth year of school starts, big drama ensues.'
+ );
```
</TabPanel>
@@ -70,8 +83,7 @@ The functions we'll cover in this guide are:
Converts your data into searchable "tokens". `to_tsvector()` stands for "to text search vector". For example:
```sql
-select to_tsvector('green eggs and ham')
-
+select to_tsvector('green eggs and ham');
-- Returns 'egg':2 'green':1 'ham':4
```
diff --git a/apps/docs/pages/guides/database/functions.mdx b/apps/docs/pages/guides/database/functions.mdx
index fda28116abe..7d55d1e7e01 100644
--- a/apps/docs/pages/guides/database/functions.mdx
+++ b/apps/docs/pages/guides/database/functions.mdx
@@ -138,7 +138,8 @@ create table planets (
name text
);
-insert into planets (id, name)
+insert into planets
+ (id, name)
values
(1, 'Tattoine'),
(2, 'Alderaan'),
@@ -150,7 +151,8 @@ create table people (
planet_id bigint references planets
);
-insert into people (id, name, planet_id)
+insert into people
+ (id, name, planet_id)
values
(1, 'Anakin Skywalker', 1),
(2, 'Luke Skywalker', 1),
diff --git a/apps/docs/pages/guides/database/json.mdx b/apps/docs/pages/guides/database/json.mdx
index 969fdb74a77..60bbda028ee 100644
--- a/apps/docs/pages/guides/database/json.mdx
+++ b/apps/docs/pages/guides/database/json.mdx
@@ -221,12 +221,11 @@ Select the title, description, price, and age range for each book.
```sql
select
title,
- metadata -> 'description' AS description,
+ metadata -> 'description' as description,
metadata -> 'price' as price,
metadata -> 'ages' -> 0 as low_age,
metadata -> 'ages' -> 1 as high_age
-from
- books;
+from books;
```
</TabPanel>
diff --git a/apps/docs/pages/guides/database/sql-to-api.mdx b/apps/docs/pages/guides/database/sql-to-api.mdx
index 636addcf3b9..6c17121d110 100644
--- a/apps/docs/pages/guides/database/sql-to-api.mdx
+++ b/apps/docs/pages/guides/database/sql-to-api.mdx
@@ -11,10 +11,11 @@ export const meta = {
Select a set of columns from a single table with where, order by, and limit clauses.
```sql
-select first_name, last_name, team_id, age from players
+select first_name, last_name, team_id, age
+from players
where age between 20 and 24 and team_id <> 'STL'
order by last_name, first_name desc
-limit 20
+limit 20;
```
```js
@@ -32,8 +33,9 @@ const { data, error } = await supabase
Select all columns from a single table with a complex where clause: OR AND OR
```sql
-select * from players
-where ((team_id = 'CHN' or team_id is null) and (age > 35 or age is null))
+select *
+from players
+where ((team_id = 'CHN' or team_id is null) and (age > 35 or age is null));
```
```js
@@ -48,8 +50,9 @@ const { data, error } = await supabase
Select all columns from a single table with a complex where clause: AND OR AND
```sql
-select * from players
-where ((team_id = 'CHN' and age > 35) or (team_id <> 'CHN' and age is not null))
+select *
+from players
+where ((team_id = 'CHN' and age > 35) or (team_id <> 'CHN' and age is not null));
```
```js
@@ -62,8 +65,9 @@ const { data, error } = await supabase
Get a count of rows, but don't return any data.
```sql
-select count(*) from players
-where team_id = 'NYM'
+select count(*)
+from players
+where team_id = 'NYM';
```
```js
diff --git a/apps/docs/pages/guides/platform/database-usage.mdx b/apps/docs/pages/guides/platform/database-usage.mdx
index 6ce6385770d..41b6ec846f9 100644
--- a/apps/docs/pages/guides/platform/database-usage.mdx
+++ b/apps/docs/pages/guides/platform/database-usage.mdx
@@ -13,9 +13,8 @@ For an instantaneous live view of the DB size, you can execute in Postgres:
```sql
select
- sum(pg_database_size (pg_database.datname)) / (1024 * 1024) as db_size_mb
-from
- pg_database;
+ sum(pg_database_size(pg_database.datname)) / (1024 * 1024) as db_size_mb
+from pg_database;
```
This value is also reported in the [database settings page](https://app.supabase.com/project/_/settings/database).
diff --git a/apps/docs/pages/guides/platform/logs.mdx b/apps/docs/pages/guides/platform/logs.mdx
index f7d0f4d14be..2f1e8d79dd4 100644
--- a/apps/docs/pages/guides/platform/logs.mdx
+++ b/apps/docs/pages/guides/platform/logs.mdx
@@ -168,7 +168,7 @@ Each log event stores metadata an array of objects with multiple levels, and can
For example, to query the edge logs without any joins:
```sql
-select timestamp, metadata from edge_logs t
+select timestamp, metadata from edge_logs as t;
```
The resulting `metadata` key is rendered as an array of objects in the Logs Explorer. In the following diagram, each box represents a nested array of objects:
@@ -183,10 +183,11 @@ To query for a nested value, add a join for each array level:
```sql
select timestamp, request.method, header.cf_ipcountry
-from edge_logs t
-cross join unnest(t.metadata) as metadata
-cross join unnest(metadata.request) as request
-cross join unnest(request.headers) as header
+from
+ edge_logs as t
+ cross join unnest(t.metadata) as metadata
+ cross join unnest(metadata.request) as request
+ cross join unnest(request.headers) as header;
```
This surfaces the following columns available for selection:
@@ -217,17 +218,19 @@ Instead, select only the values required.
-- ❌ Avoid doing this
select
datetime(timestamp),
- m as metadata -- <- metadata contains many nested keys
-from edge_logs t
-cross join unnest(t.metadata) as m;
+ m as metadata -- <- metadata contains many nested keys
+from
+ edge_logs as t
+ cross join unnest(t.metadata) as m;
-- ✅ Do this
select
-datetime(timestamp),
-r.method -- <- select only the required values
-from edge_logs t
-cross join unnest(t.metadata) as m
-cross join unnest(m.request) as r
+ datetime(timestamp),
+ r.method -- <- select only the required values
+from
+ edge_logs as t
+ cross join unnest(t.metadata) as m
+ cross join unnest(m.request) as r;
```
### Examples and Templates
@@ -238,11 +241,12 @@ For example, you can enter the following query in the SQL Editor to retrieve eac
```sql
select datetime(timestamp), h.x_real_ip
-from edge_logs
+from
+ edge_logs
cross join unnest(metadata) as m
- cross join unnest(m.request) AS r
- cross join unnest(r.headers) AS h
-where h.x_real_ip is not null and r.method = "GET"
+ cross join unnest(m.request) as r
+ cross join unnest(r.headers) as h
+where h.x_real_ip is not null and r.method = "GET";
```
export const Page = ({ children }) => <Layout meta={meta} children={children} />
diff --git a/apps/docs/pages/guides/resources/postgres/which-version-of-postgres.mdx b/apps/docs/pages/guides/resources/postgres/which-version-of-postgres.mdx
index 29bea3ab32b..3a04c7ce06a 100644
--- a/apps/docs/pages/guides/resources/postgres/which-version-of-postgres.mdx
+++ b/apps/docs/pages/guides/resources/postgres/which-version-of-postgres.mdx
@@ -12,7 +12,7 @@ Run the following query using the [SQL Editor](https://app.supabase.com/project/
```sql
select
- version ();
+ version();
```
Which should return something like:
diff --git a/apps/docs/pages/guides/storage/quickstart.mdx b/apps/docs/pages/guides/storage/quickstart.mdx
index 7309f2730af..ba0f54e6943 100644
--- a/apps/docs/pages/guides/storage/quickstart.mdx
+++ b/apps/docs/pages/guides/storage/quickstart.mdx
@@ -41,8 +41,10 @@ client libraries. Here we create a bucket called "avatars":
```sql
-- Use Postgres to create a bucket.
-insert into storage.buckets (id, name)
-values ('avatars', 'avatars');
+insert into storage.buckets
+ (id, name)
+values
+ ('avatars', 'avatars');
```
</TabPanel>
diff --git a/apps/docs/pages/learn/auth-deep-dive/auth-policies.mdx b/apps/docs/pages/learn/auth-deep-dive/auth-policies.mdx
index 00caf731fbc..94fe1602450 100644
--- a/apps/docs/pages/learn/auth-deep-dive/auth-policies.mdx
+++ b/apps/docs/pages/learn/auth-deep-dive/auth-policies.mdx
@@ -158,8 +158,8 @@ Supabase comes with two built-in helper functions: `auth.uid()` and `auth.jwt()`
To create your own functions, navigate to the SQL editor and create a a new query.
```sql
-create or replace function user_agent()
-returns text
+create or replace function user_agent()
+returns text
language sql
as $$
select nullif(current_setting('request.headers', true)::json->>'user-agent', '')::text;
diff --git a/apps/docs/pages/learn/auth-deep-dive/auth-row-level-security.mdx b/apps/docs/pages/learn/auth-deep-dive/auth-row-level-security.mdx
index 95a03060bc9..c75b446e972 100644
--- a/apps/docs/pages/learn/auth-deep-dive/auth-row-level-security.mdx
+++ b/apps/docs/pages/learn/auth-deep-dive/auth-row-level-security.mdx
@@ -45,12 +45,16 @@ Let's say we create a leaderboard table. We want people on our website to be abl
```sql
create table leaderboard (
- name text,
- score int
+ name text,
+ score int
);
-insert into leaderboard(name, score)
-values ('Paul', 100), ('Leto', 50), ('Chani', 200);
+insert into leaderboard
+ (name, score)
+values
+ ('Paul', 100),
+ ('Leto', 50),
+ ('Chani', 200);
```
Now let's set up a client to read the data, I've created a repl here to show a living example: [https://replit.com/@awalias/supabase-leaderboard-demo#index.js](https://replit.com/@awalias/supabase-leaderboard-demo#index.js). If you copy the snippet you can plug in your own Supabase URL and anon key.