Advanced Queries
prestd allows you to do some advanced queries, but with some limitations in order to make the URL and parameters as clean as possible.
Filter range
It is common to query a database in a range of time, e.g:
I need all records that were created from
1997-11-03-03
to1997-12-05
.
created_at
field is a timestamp field, so you can use the $gte
and $lte
operators to filter by date range.
How to do it in prestd?
There are other types of operators, see them all here.
JOIN
HTTP verb GET
, allows you to join tables, with 1 level of depth - unfortunately the syntax is not so friendly so we limited it to 1 level only.
Parameters:
Type:
inner
left
right
outer
Table used in the join
Table.field - table name dot field
Operator:
$eq
$lt
$gt
$lte
$gte
Table2.field - table name dot field
Using query string to JOIN tables, example:
If you need multiple joins, we recommend using the queues feature (sql script execution).
JSONb support
PostgreSQL offers type for storing jsonb data. To implement efficient query mechanisms for these data types.
Example of how to do insertion via cURL
cURL
Fields:
id:
INT
data:
JSONB
Full Text Search (with tsquery)
Full Text Searching (or just text search) provides the capability to identify natural-language documents that satisfy a query, and optionally to sort them by relevance to the query. The most common type of search is to find all documents containing given query terms and return them in order of their similarity to the query. Notions of query and similarity are very flexible and depend on the specific application. The simplest search considers query as a set of words and similarity as the frequency of query words in the document.
Is native feature of PostgreSQL since version 8.3, read more here.
A tsquery value stores lexemes that are to be searched for, and combines them honoring the Boolean operators & (AND), | (OR), and ! (NOT). Parentheses can be used to enforce grouping of the operators.
SELECT 'fat & rat'::tsquery;
Set language
You can specify the language you want to tokenize in, for example: portuguese
Language list:
simple
arabic
danish
dutch
english
finnish
french
german
hungarian
indonesian
irish
italian
lithuanian
nepali
norwegian
portuguese
romanian
russian
spanish
swedish
tamil
turkish
To see all the languages available in your PostgreSQL run this query:
Batch Insert
HTTP verb POST
, you can insert many rows at once using batch endpoint /batch/...
.
JSON DATA:
The default insert method is using multiple tuple values like insert into table values ("value", 123), ("other", 456)
. Returns inserted rows.
You can change this behavior using the header Prest-Batch-Method
with value copy
. It's useful for large insertions, but the return is empty.
Last updated