Why this function don't bring the results? In influxdb.
select * from items.movement
where time > now() - 7d
and oldContainerId='aaaaaa'
and newContainerId='aaaaaaa'
Thanks.
I solved with this:
select * from series
where time > now() - 7d
and newContainerId = 'aaaa'
limit 100;
select * from series
where time > now() - 7d
and oldContainerId = 'aaaa'
limit 100
select * from "items.movement" where time > now() - 7d and oldContainerId = 'aaaaaa' and newContainerId = 'aaaaaaa'
NOTE : Space and double quotes matters.
Related
I'm experimenting with subqueries in InfluxDB (shell version: 1.7.4), and I've encountered this issue:
> SELECT "value" AS "legacy" FROM my_table WHERE time >= '2022-12-22 18:00:00' AND entityId = '637deee12ccd09000b8bea57' tz('Europe/Athens')
name: my_table
time legacy
---- ------
2022-12-22T18:15:16.261+02:00 11
2022-12-22T19:15:30.65+02:00 12
> SELECT * FROM (SELECT "value" AS "legacy" FROM my_table WHERE time >= '2022-12-22 18:00:00' AND entityId = '637deee12ccd09000b8bea57' tz('Europe/Athens'))
>
> SELECT SUM(*) FROM (SELECT "value" AS "legacy" FROM my_table WHERE time >= '2022-12-22 18:00:00' AND entityId = '637deee12ccd09000b8bea57' tz('Europe/Athens'))
>
The second and third queries, both return an empty result. I would expect the second to return the same result as the first one, and the third to return the sum. What have I misunderstood?
I want to limit the number of result using JobSearchRestriction. I want to limit not by a condition, but by "hard coded" number. Somethig like "LIMIT 10".
Is it possible to do that in hybris using JobSearchRestriction?
Try this
SELECT * FROM {Product} LIMIT 10
or
SELECT TOP 10 * FROM {Product}
For Oracle
SELECT * FROM {Product} WHERE rownum <= 10
Though API
final FlexibleSearchQuery query = new FlexibleSearchQuery("SELECT * FROM {Product}");
query.setCount(10);
In my node app, i need to run below query and and i'm passing parameters dynamically. But it's not fetching the parameters since they are referenced inside single quotes. Suggest a solution for this.
const text = `UPDATE glacier_restore_progress
SET
status='completed',
restore_end=CURRENT_TIMESTAMP,
restore_expire=DATE_TRUNC('minutes', current_timestamp + interval '$1 minutes')
WHERE file_path = '$2' AND date_trunc('minutes', current_timestamp - interval '$1 minutes') <= restore_start`;
const values = [restoreDuration, fileKey];
await pool.query(text, values);
and the error i get is,
"bind message supplies 2 parameters, but prepared statement \"\" requires 0"
You are absolutely right; parameters cannot be inside quotes. There are a few ways we can solve this:
Taking the similarly broken example SELECT * FROM employees WHERE CURRENT_TIMESTAMP - start_date < INTERVAL '$1 years';
Have the client submit the "full" value: SELECT * FROM employees WHERE CURRENT_TIMESTAMP - start_date < INTERVAL $1;
Construct string in the query: SELECT * FROM employees WHERE CURRENT_TIMESTAMP - start_date < INTERVAL ($1 || ' years');
(interval specific) Use the fact the unit can be specified as its own keyword: SELECT * FROM employees WHERE CURRENT_TIMESTAMP - start_date < INTERVAL $1 MINUTE
My preference in this case is 1, however the most faithful to your question is 3. Be careful to use MINUTE and not MINUTES. Option 2, using the concatentation operator, is a good hack to have in your toolbelt. All answers tested in Postgres 13.
In addition to this, your parameter is likely going to bound as a number, which will get you an error. You may need to cast it to text, like so $1::TEXT
Your full query would be:
UPDATE glacier_restore_progress
SET
status = 'completed',
restore_end = CURRENT_TIMESTAMP,
restore_expire = DATE_TRUNC('minutes', CURRENT_TIMESTAMP + INTERVAL $1::TEXT MINUTE)
WHERE file_path = $2
AND DATE_TRUNC('minutes', current_timestamp - INTERVAL $1 MINUTE) <= restore_start
use this,
const text = `UPDATE glacier_restore_progress
SET
status='completed',
restore_end=CURRENT_TIMESTAMP,
restore_expire=DATE_TRUNC('minutes', current_timestamp + interval '1 minutes' * $1)
WHERE file_path = $2 AND date_trunc('minutes', current_timestamp - interval '1 minutes' * $1) <= restore_start`;
const values = [restoreDuration, fileKey];
await pool.query(text, values);
this convention is mentioned here refrence
I want to select records newer than 8 days from several tables. This is not working:
self._getRawData = sql.SQL("SELECT * FROM {} WRERE {} > NOW() - INTERVAL {}")
...
cur = self._conn.cursor()
cur.execute(self._getRawData.format(sql.Identifier('MyTS.MyTable'), \
sql.Identifier('Timestamp'), \
sql.Identifier('8 days')))
gives error:
psycopg2.errors.SyntaxError: syntax error at or near ""Timestamp""
Below is working OK, but I want to implement sql.SQL for several tables. Any advice?
statement = "SELECT * FROM \"MyTS\".\"MyTable\" WHERE \"Timestamp\" > NOW() - INTERVAL \'8 days\'"
cur = self._conn.cursor()
cur.execute(statement)
Update: Thanks to the comments, I solved it with
self._getRawData = sql.SQL("SELECT * FROM {}.{} WHERE {} > NOW() - INTERVAL {}")
...
sql.Literal('8 days')))
I need to replicate the linux command "date +%s%3N" in SQL Developer. I have tried the below code sample but it returns with a different value. I have also done extensive searching Google with no luck.
select to_char((extract(day from (systimestamp - timestamp '1970-01-01 00:00:00')) * 86400000
+ extract(hour from (systimestamp - timestamp '1970-01-01 00:00:00')) * 3600000
+ extract(minute from (systimestamp - timestamp '1970-01-01 00:00:00')) * 60000
+ extract(second from (systimestamp - timestamp '1970-01-01 00:00:00')) * 1000) * 1000) unix_time
from dual;
The date +%s%3N command returns something like:
1475615656692870653
Whereas the above code sample returns something like:
1475594089419116
The date command returns a longer and larger number than the code sample even though it was run before the code sample. The ultimate solution would be a direct utility in Oracle if possible. If not, possibly invoking the date command within Oracle would work.
Try this one:
CREATE OR REPLACE FUNCTION GetUnixTime RETURN INTEGER IS
dsInt INTERVAL DAY(9) TO SECOND;
res NUMBER;
BEGIN
dsInt := CURRENT_TIMESTAMP - TIMESTAMP '1970-01-01 00:00:00 UTC';
res:= EXTRACT(DAY FROM dsInt)*24*60*60
+ EXTRACT(HOUR FROM dsInt)*60*60
+ EXTRACT(MINUTE FROM dsInt)*60
+ EXTRACT(SECOND FROM dsInt);
RETURN ROUND(1000*res);
END GetUnixTime;
ROUND(1000*res) will return Unix time in Milliseconds, according to your question it is not clear whether you like to get Milliseconds, Microseconds or even Nanoseconds. But it is quite obvious how to change the result to desired value.
This function considers your local time zone and time zone of Unix epoch (which is always UTC)
If you don't like a function, you can write it at a query of course:
SELECT
ROUND(EXTRACT(DAY FROM CURRENT_TIMESTAMP - TIMESTAMP '1970-01-01 00:00:00 UTC')*24*60*60
+ EXTRACT(HOUR FROM CURRENT_TIMESTAMP - TIMESTAMP '1970-01-01 00:00:00 UTC')*60*60
+ EXTRACT(MINUTE FROM CURRENT_TIMESTAMP - TIMESTAMP '1970-01-01 00:00:00 UTC')*60
+ EXTRACT(SECOND FROM CURRENT_TIMESTAMP - TIMESTAMP '1970-01-01 00:00:00 UTC')
* 1000) AS unix_time
FROM dual;
I ended up going with using oscommands through the method described in this link here http://www.orafaq.com/scripts/plsql/oscmd.txt. The solutions below were a step in the right direction, however, other parts of the script we were making were running into issues. Using oscommands solved all of our issues. With the method mentioned in the link, I was simply able to type
l_time := oscomm('/bin/date +%s%3N');
to get the correct number.