Is there a LAG function in QuestDB? - questdb

I currently store data in QuestDB. I need to return the result of subtraction between subsequent field values. Does QuestDB have such a function out of the box in the SQL query syntax? This is what InfluxDB has got: https://docs.influxdata.com/influxdb/v1.8/query_language/functions/#difference

This is not yet supported, but there is a ticket to track addition of LAG/LEAD functions here: https://github.com/questdb/questdb/issues/1268

Related

Textfield with autocomplete

I have several fields that contain exactly the same sql query! Is it possible to place the sql question centrally in APEX in the same way as list of values or as a function in oracle? I am using APEX 18.2
Here are two extended solutions
Pipelined SQL
https://smart4solutions.nl/blog/on-apex-lovs-and-how-to-define-their-queries/
Dynamic SQL
http://stevenfeuersteinonplsql.blogspot.com/2017/01/learn-to-hate-repetition-lesson-from.html
Call me dense, but I don't think I understand why you'd have multiple fields (presumably on the same form) whose source is the same SQL query.
Are you passing a parameter to the SQL to get a different value for each field?
If you are passing a parameter to the SQL query, why not create a database view to hold the query, then pass the parameter to the view. That way, if you need to change it, it's in one place.
If they really are all the same value from the same query, how about using the SQL for one field/page_item, then make the source for the others be the first page item?
I would create a hidden item with the query in the source as text and use &HIDDEN_ITEM_NAME. to reference its value in the source of any item I was trying to display the query.
Finally isolved it with a function and use the type PL/SQL Function Body returning SQL Query in APEX, then i have all in one place. I created a function in SQL developer that returns a SQL query.

Update multiple field values matching a condition in InfluxDB

In an InfluxDB measurement, how can the field values of points matching a query be updated? Is this still not easily doable as of v1.6?
As the example in that GitHub ticket suggested, what's the cleanest way of achieving something like this?
UPDATE access_log SET username='something' WHERE mac='xxx'
Anything better than driving it all from the client by updating individual points?
Q: How can the field values of points matching a query be updated? Is this still not easily doable as of v1.4?
A: From the best of my knowledge, there isn't an easy way to accomplish update in version 1.4 yet.
Field value of a point can only be updated by overriding. That is, to overwrite its value you'll need to know the details of your points. These details include its timestamp and series information, which is the measurement it reside and its corresponding tags.
Note: This "update" strategy can only be used for changing the field value but not tag value. To update a tag value you'll need to first DELETE the point data first and rewrite the entire point data with the updated tag and value.
Q: Anything better than driving it all from the client by updating individual points?
A: Influxdb supports multi-point write. So if you can build a filter to pre-select a small dataset of points, modify their field values and then override them in bulk.
Update is possible and would take the format:
INSERT measurement,tag_name=tag_value_no_quotes value_key_1=value_value_1,value_key_2=value_value_2 time
for example where I want to update the line with tag my_box at time 1526988768877018669 on the box measurement:
INSERT box,box_name=my_box item_1='apple',item_2='melon' 1526988768877018669

django database functions cumulative count?

is their a way to create cumulative count using/customizing django database functions. this built-in query gets the number of items for each year. what if we need the number of items before that year ?
items.values('year').annotate(nb=Count('id'))
This functionality is built-in in django. You can combine order_by, values and annotate to get what you want:
Item.objects.order_by('year').values('year').annotate(nb=Count('id'))
For the official docs, see: aggregation. If the sample doesn't work I'll need more information about the model to give you the correct call. Please provide the full model and, if required, some sample data.

Comparing two SQLite databases in C++

I have two C++ functions, which each construct an SQLite database.
First function constructs database version 1, and then upgrades it to newest version by adding all tables/columns that have been added to the database since the first version. Another function constructs a database that is already in the newest version. As result, each function gives one database that has all necessary tables and columns, but no values.
I wish to write an unit test that compares the results of those two functions. I want to test that they have exactly the same tables and columns, and that all columns have the same CHECK and NOT NULL constraints. I only need to compare columns and tables, because the databases have no values in them at this point.
I would prefer to get the differences in a human readable form (to place them in an error message), but a boolean value (different/not different) is also fine.
How can I do that, given that both databases are in different variables and I cannot combine them?
There are other questions that suggest external applications for this, but can I do it in a simple way in C++? One possibility is to execute some SQL commands for each database, and compare the results in a for loop, but which commands do I need?
You can read the sqlite_master table to read the SQL used to create each table and compare that:
SELECT name, type, sql FROM sqlite_master;
For more information on sqlite_master, consult the SQLite documentation.

How do I update a value in a row in MySQL using Connector/C++

I have a simple database and want to update an int value. I initially do a query and get back a ResultSet (sql::ResultSet). For each of the entries in the result set I want to modify a value that is in one particular column of a table, then write it back out to the database/update that entry in that row.
It is not clear to me based on the documentation how to do that. I keep seeing "Insert" statements along with updates - but I don't think that is what I want - I want to keep most of the row of data intact - just update one column.
Can someone point me to some sample code or other clear reference/resource?
EDIT:
Alternatively, is there a way to tell the database to update a particular field (row/col) to increment an int value by some value?
EDIT:
So what is the typical way that people use MySQL from C++? Use the C api or the mysql++? I guess I chose the wrong API...
From a quick scan of the docs it appears Connector/C++ is a partial implementation of the Java JDBC API for C++. I didn't find any reference to updateable result sets so this might not be possible. In Java JDBC the ResultSet interface includes support for updating the current row if the statement was created with ResultSet.CONCUR_UPDATABLE concurrency.
You should investigate whether Connector/C++ supports updateable resultsets.
EDIT: To update a row you will need to use a PreparedStatement containing an SQL UPDATE, and then the statement's executeUpdate() method. With this approach you must identify the record to be update with a WHERE clause. For example
update users set userName='John Doe' where userID=?
Then you would create a PreparedStatement, set the parameter value, and then executeUpdate().