mirror of
https://github.com/supabase/supabase.git
synced 2026-10-09 11:25:06 +03:00
Closes DOCS-1057 Contributes to DOCS-1052 ## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## Problem We have hundreds of MDX lint warnings in our docs going against style best practices. ## Solution Remove and replace in context the following: - PostgreSQL. There was only one. There was concern about exceptions, but I found none. - Just - Quickly - Actually ### What changed Edits follow the [Google developer documentation style guide](https://developers.google.com/style): concise, direct, active voice. The flagged words were removed when the sentence still read well, or replaced when meaning needed to be preserved. ### Common patterns | Flagged word | Approach | Example | |---|---|---| | **just** (filler) | Removed | "you just installed" → "you installed" | | **just** (limiting) | **only** | "just one row" → "only one row" | | **just like** | **like** / **the same as** | "function just like regular users" → "function like regular users" | | **not just** | **not only** | "not just errors" → "not only errors" | | **quickly** (performance) | **efficiently** or removed | "find rows quickly" → "find rows efficiently" | | **quickly** (time) | **soon** / **rapidly** / removed | "expires too quickly" → "expires too soon" | | **actually** (filler) | Removed | "actually execute" → "execute"; "is actually the most common" → "is the most common" | ## Tophatting 1. See the diff. 2. See that content continues to make sense in context. 3. Locally, `cd apps/docs` and run `pnpm run lint:mdx`. 4. Search for "just," "actually," "quickly", and "PostgreSQL" and see there are 0 warnings. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Updated wording across quickstarts, guides, and troubleshooting articles for grammar, clarity, and consistent step-by-step phrasing. * Clarified key concepts including Row Level Security policy evaluation across Supabase products, deferred foreign key constraint behavior, and when `EXPLAIN ANALYZE` executes queries (and related side effects). * Refined several troubleshooting instructions and added guidance to cap log payload size to reduce billed Logs Ingest volume. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nik Richers <nrichers@gmail.com> Co-authored-by: Chris Chinchilla <chris.ward@supabase.io>
159 lines
3.7 KiB
Plaintext
159 lines
3.7 KiB
Plaintext
---
|
|
id: 'plv8'
|
|
title: 'plv8: JavaScript Language'
|
|
description: 'JavaScript language for Postgres.'
|
|
---
|
|
|
|
<Admonition type="deprecation">
|
|
|
|
The `plv8` extension is deprecated in projects using Postgres 17. It continues to be supported in projects using Postgres 15, but will need to dropped before those projects are upgraded to Postgres 17. See the [Upgrading to Postgres 17 notes](/docs/guides/platform/upgrading#upgrading-to-postgres-17) for more information.
|
|
|
|
</Admonition>
|
|
|
|
The `plv8` extension allows you use JavaScript within Postgres.
|
|
|
|
## Overview
|
|
|
|
While Postgres natively runs SQL, it can also run other procedural languages.
|
|
`plv8` allows you to run JavaScript code - specifically any code that runs on the [V8 JavaScript engine](https://v8.dev).
|
|
|
|
It can be used for database functions, triggers, queries and more.
|
|
|
|
## Enable the extension
|
|
|
|
<Tabs
|
|
scrollable
|
|
size="small"
|
|
type="underlined"
|
|
defaultActiveId="dashboard"
|
|
queryGroup="database-method"
|
|
>
|
|
<TabPanel id="dashboard" label="Dashboard">
|
|
|
|
1. Go to the [Database](/dashboard/project/_/database/tables) page in the Dashboard.
|
|
2. Click on **Extensions** in the sidebar.
|
|
3. Search for "plv8" and enable the extension.
|
|
|
|
</TabPanel>
|
|
<TabPanel id="sql" label="SQL">
|
|
|
|
```sql
|
|
-- Example: enable the "plv8" extension
|
|
create extension plv8;
|
|
|
|
-- Example: disable the "plv8" extension
|
|
drop extension if exists plv8;
|
|
```
|
|
|
|
Even though the SQL code is `create extension`, this is the equivalent of enabling the extension.
|
|
To disable an extension, call `drop extension`.
|
|
|
|
Procedural languages are automatically installed within `pg_catalog`, so you don't need to specify a schema.
|
|
|
|
</TabPanel>
|
|
</Tabs>
|
|
|
|
## Create `plv8` functions
|
|
|
|
Functions written in `plv8` are written like any other Postgres functions, only
|
|
with the `language` identifier set to `plv8`.
|
|
|
|
```sql
|
|
create or replace function function_name()
|
|
returns void as $$
|
|
// V8 JavaScript
|
|
// code
|
|
// here
|
|
$$ language plv8;
|
|
```
|
|
|
|
You can call `plv8` functions like any other Postgres function:
|
|
|
|
<Tabs
|
|
scrollable
|
|
size="small"
|
|
type="underlined"
|
|
defaultActiveId="sql"
|
|
queryGroup="language"
|
|
>
|
|
<TabPanel id="sql" label="SQL">
|
|
|
|
```sql
|
|
select function_name();
|
|
```
|
|
|
|
</TabPanel>
|
|
<TabPanel id="js" label="JavaScript">
|
|
|
|
```js
|
|
const { data, error } = supabase.rpc('function_name')
|
|
```
|
|
|
|
</TabPanel>
|
|
<$Show if="sdk:kotlin">
|
|
<TabPanel id="kotlin" label="Kotlin">
|
|
|
|
```kotlin
|
|
val data = supabase.postgrest.rpc("function_name")
|
|
```
|
|
|
|
</TabPanel>
|
|
</$Show>
|
|
</Tabs>
|
|
|
|
## Examples
|
|
|
|
### Scalar functions
|
|
|
|
A [scalar function](https://plv8.github.io/#scalar-function-calls) is anything that takes in some user input and returns a single result.
|
|
|
|
```sql
|
|
create or replace function hello_world(name text)
|
|
returns text as $$
|
|
|
|
let output = `Hello, ${name}!`;
|
|
return output;
|
|
|
|
$$ language plv8;
|
|
```
|
|
|
|
### Executing SQL
|
|
|
|
You can execute SQL within `plv8` code using the [`plv8.execute` function](https://plv8.github.io/#plv8-execute).
|
|
|
|
```sql
|
|
create or replace function update_user(id bigint, first_name text)
|
|
returns smallint as $$
|
|
|
|
var num_affected = plv8.execute(
|
|
'update profiles set first_name = $1 where id = $2',
|
|
[first_name, id]
|
|
);
|
|
|
|
return num_affected;
|
|
$$ language plv8;
|
|
```
|
|
|
|
### Set-returning functions
|
|
|
|
A [set-returning function](https://plv8.github.io/#set-returning-function-calls) is anything that returns a full set of results - for example, rows in a table.
|
|
|
|
```sql
|
|
create or replace function get_messages()
|
|
returns setof messages as $$
|
|
|
|
var json_result = plv8.execute(
|
|
'select * from messages'
|
|
);
|
|
|
|
return json_result;
|
|
$$ language plv8;
|
|
|
|
select * from get_messages();
|
|
```
|
|
|
|
## Resources
|
|
|
|
- Official [`plv8` documentation](https://plv8.github.io/)
|
|
- [plv8 GitHub Repository](https://github.com/plv8/plv8)
|