Standard Library
Library Reference
The supabase platform nudges users to collocate compute with data than is typical for PostgreSQL backed applications. As a result, the PostgreSQL standard library
All examples assume supautils
was created in a schema named supa
.
Array
index
Return one-based index in the array of the first item whose value is equal to x. Returns null
if there is no such item.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 select supa . index ( array [ 'a' , 'b' , 'c' ], 'c' );
index
-------
3
( 1 row )
select supa . index ( array [ 1 , 2 , 3 ], 4 );
index
-------
( 1 row )
select supa . index ( array []:: int [], 1 );
index
-------
( 1 row )
select supa . index ( null :: int [], 1 );
index
-------
( 1 row )
reverse
Return an array that is in reverse order from the input array.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 select supa . reverse ( array [ 'a' , 'b' , 'c' ]);
reverse
---------
{ c , b , a }
( 1 row )
select supa . reverse ( array [ 1 , 2 , 3 ]);
reverse
---------
{ 3 , 2 , 1 }
( 1 row )
select supa . reverse ( array []:: int []);
reverse
---------
( 1 row )
select supa . reverse ( null :: int []);
reverse
---------
( 1 row )
unique
Return an array containing unique elements of the input array.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 select supa . unique ( array [ 'a' , 'a' , 'b' , 'a' ]);
unique
--------
{ a , b }
( 1 row )
select supa . unique ( array [ 1 , 2 , 3 , 2 ]);
unique
---------
{ 1 , 2 , 3 }
( 1 row )
select supa . unique ( array []:: int []);
unique
--------
( 1 row )
select supa . unique ( null :: int []);
unique
--------
( 1 row )
Inspect
table_row_count_estimate
Return the approximate number of rows in a table.
1
2
3
4
5
6
7
8
9
10
11
12
13 begin ;
select *
into public . account
from generate_series ( 1 , 100 );
analyze public . account ;
select supa . table_row_count_estimate ( 'public.account' :: regclass );
table_row_count_estimate
--------------------------
100
( 1 row )
rollback ;
query_row_count_estimate
Return the approximate number of rows to be selected in a query.
select supa . query_row_count_estimate ( $$
select *
from generate_series ( 1 , 100 );
$$ :: text );
query_row_count_estimate
--------------------------
100
( 1 row )