Questions tagged [postgrest]

PostgREST serves a fully RESTful API from any existing PostgreSQL database. It provides a cleaner, more standards-compliant, faster API. It differs from the other emerging API servers by taking an opinionated stance on the full implementation of API by being operationally sound and simple to deploy, by delivering built-in security with JSON Web Tokens plus database roles, and by fully embracing the relational model.

Introduction

PostgREST is a standalone web server that turns your PostgreSQL database directly into a RESTful API. The structural constraints and permissions in the database determine the API endpoints and operations.

Motivation

Using PostgREST is an alternative to manual CRUD programming. Custom API servers suffer problems. Writing business logic often duplicates, ignores or hobbles database structure. Object-relational mapping is a leaky abstraction leading to slow imperative code. The PostgREST philosophy establishes a single declarative source of truth: the data itself.

Declarative Programming

It's easier to ask Postgres to join data for you and let its query planner figure out the details than to loop through rows yourself. It's easier to assign permissions to db objects than to add guards in controllers. (This is especially true for cascading permissions in data dependencies.) It's easier to set constraints than to litter code with sanity checks.

Leakproof Abstraction

There is no ORM involved. Creating new views happens in SQL with known performance implications. A database administrator can now create an API from scratch with no custom programming.

Embracing the Relational Model

In 1970 E. F. Codd criticized the then-dominant hierarchical model of databases in his article A Relational Model of Data for Large Shared Data Banks. Reading the article reveals a striking similarity between hierarchical databases and nested http routes. With PostgREST we attempt to use flexible filtering and embedding rather than nested routes.

One Thing Well

PostgREST has a focused scope. It works well with other tools like Nginx. This forces you to cleanly separate the data-centric CRUD operations from other concerns. Use a collection of sharp tools rather than building a big ball of mud.

136 questions
2
votes
1 answer

Can we use PostgREST API with Azure

I am working with PostgreSQL which is present in Azure. I want to implement API for PostgreSQL database with PostgREST API. Is it possible to do that? Thanks in advance
RevanthOleti
  • 53
  • 2
  • 6
2
votes
0 answers

postgrest `stack test` gives: FATAL: database "test/create_test_db "postgres://postgres:pwd@database-host" tes" does not exist

stack test gives error: postgrest> test (suite: spec) psql: warning: extra command-line argument "-f" ignored psql: warning: extra command-line argument "test/fixtures/database.sql" ignored psql: FATAL: database "test/create_test_db…
puzzled
  • 77
  • 4
2
votes
1 answer

curl syntax for PostgREST query

Using PostgREST (http://postgrest.org/en/v5.2/api.html) version 5.2 against a Postgres 11 database, the following curl command: curl -X GET http://192.18.11.13:5741/workorder?acctid=eq.SunnySide&workorderid=eq.0001 generates the following trace in…
drobin
  • 286
  • 2
  • 6
2
votes
1 answer

Postgres | IF statement with OR conditional

I have a stored procedure which is used to validate an incoming variable. If the variable is not 'maker' or 'member', then it should throw an error. If the variable is of the two above mentioned, it should continue normal processing. The current…
2
votes
2 answers

Increasing time before 504 time-out using python requests

I am using the requests module to query a relatively large PostgRES database (~14 GB), accessible via a PostgREST API, hosted on a simple server set up by a peer. When I make simple API calls, such…
2
votes
1 answer

Postgrest filter does not seem work with fields from related table

I would like to retrieve records of kiscourse where the related joblist.job has a value that contains tech within the joblist.job string value. This returns the expected results: /joblist?select=job,kiscourse_id(*)&limit=10&job=ilike.*tech* This…
Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
2
votes
1 answer

Periodic drop in throughput of nginx reverse proxy, what can it be?

I am load testing a t2.micro box that has nginx and postgrest running in docker containers. Nginx acts as a proxy in front of postgrest. If i go directly to the upstream (postgrest) i get a nice graph (peaks at about 900/rps) If i go through nginx,…
1
vote
1 answer

Formating a csv file in Postgrest API REST to insert the data

The goal is to select a CSV file on a computer to insert the data in a distant PostgreSQL table using POST request. Once the CSV file has been selected in a html page, a click on a button causes it to be processed in the browser. const btnIntegrer =…
Leehan
  • 145
  • 7
1
vote
1 answer

How to access a Supabase Vault Secret from my app?

I am trying to query a secret from supabase vault into my app but I am not sure how to do that. Do I need to create a rpc function or is it possible to use the postgREST API? For the latter, what is the right endpoint? Thanks
Christian
  • 834
  • 7
  • 18
1
vote
1 answer

How do I transform query string parameters in nginx?

How do I use nginx to transform incoming query string parameters according to some rule? In particular, I want to prepend a prefix onto each and every query string parameter value. In particular, I would like to do the following. Given this…
1
vote
1 answer

Querying sub-sub table in Supabase / Grandchild relationship in JOIN QUERY

Given the following schema: CREATE TABLE organization ( org_name text NOT NULL, PRIMARY KEY (org_name) ); CREATE TABLE teams ( org_name text NOT NULL, team_name text NOT NULL, PRIMARY KEY (org_name, team_name), FOREIGN KEY…
Mansueli
  • 6,223
  • 8
  • 33
  • 57
1
vote
1 answer

Configure NGINX to proxy HTTPS requests to a server HTTP

I'm trying to use PostgREST API to deal with some queries in a PostgreSQL server, but the API doesn't accept HTTPS request as stated in the API documentation: PostgREST aims to do one thing well: add an HTTP interface to a PostgreSQL database. To…
Marcio Lino
  • 379
  • 2
  • 15
1
vote
1 answer

postgREST - Select query from two columns with one IN condition

I have a postgesql table test_1 as follows : || ID || container_id || product_id || ----------------------------------------------------------------------------- || 1 || 1 || …
renaise21
  • 169
  • 2
  • 9
1
vote
1 answer

Does PostREST have a null-safe not-equal operator, like IS DISTINCT FROM?

I'm making some simple PostgREST queries on a table with network device properties. It seems that eq and not.eq both exclude null values. I've learned that that's a “feature” of PostgreSQL, and can be worked around with the IS DISTINCT FROM…
Jacktose
  • 709
  • 7
  • 21
1
vote
1 answer

How to select and order rows based on number of matched elements in array from foreign table in postgREST

I'm creating simple supabase application and I want to construct postgREST query to select recipes and order them ascending by number of matched_ingredients Right now I'm stuck on…
1 2
3
9 10