A PostreSQL "interval "does not complie - sql

I have the following condition in a Postgres query:
…where (o.estimate_close_date + m.MonthNumber) < (o.estimate_close_date + **interval** '1 month' * o.duration_months)…
This test is compiled OK while it is just an SQL text.
But when a put this on a VIEW I get the following compilation error:
SQL Error [42601]: ERROR: syntax error at or near "months"
Position: 171
What it is ? I fin the root case is the "interval"
; but whet exactly to do with it?

Related

Invalid timeline function when using derivative function in TDengine

I'm executing a derivative function in TDengine database, and it reports an error.
My sql statement is:
select derivative(errors, 1s, 1) as errors from (select sum(errors) as errors from log.dnodes_info where ts>="2022-12-06 14:08:42" and ts < "2022-12-06 15:00:00" interval(1s));
The error information is:
DB error: Invalid timeline function (0.002248s)
If I execute the following sql directly, it is ok.
select sum(errors) as errors from log.dnodes_info where ts>="2022-12-06 14:08:42" and ts < "2022-12-06 15:00:00" interval(1s) limit 10;
error information
Do I use it in a wrong way?

Nested select statements in impala sql

I have the following SQL query in impala
SELECT currentdate,close
FROM ( SELECT * FROM spyprice)
Where currentdate between '2015-01-16' and '2016-06-17';
And it is giving me the error:
Starting Impala Shell without Kerberos authentication
ERROR: AnalysisException: Syntax error in line 15:
WHERE currentdate BETWEEN '2015-01-16' and '2016-06-17'
^
Encountered: WHERE
Expected: AS, DEFAULT, IDENTIFIER
CAUSED BY: Exception: Syntax error
Anyone knows what's going on?
Thanks in advance!
#James Xiang The right syntax of the query statement is :
SELECT a.currentdate, a.close FROM
(
SELECT * FROM spyprice
) a
Where a.currentdate between '2015-01-16' and '2016-06-17';

ERROR: syntax error at or near "group" in SQL query

Hello guys I am running this query to get some data from database table.
select pickup, supplier, sum(price)
from myrent_prices_to
where (pickup BETWEEN '2018-01-01' and '2018-07-31')
and location SIMILAR TO '(%)'
and vehicleclass SIMILAR TO '(%)'
and supplier SIMILAR TO '(%)'
group by pickup, supplier
But it is giving me error below:
org.eclipse.birt.report.engine.api.EngineException: Error happened
while running the report. at
org.eclipse.birt.report.engine.api.impl.DatasetPreviewTask.doRun(DatasetPreviewTask.java:135)
at
org.eclipse.birt.report.engine.api.impl.DatasetPreviewTask.runDataset(DatasetPreviewTask.java:97)
at
org.eclipse.birt.report.engine.api.impl.DatasetPreviewTask.execute(DatasetPreviewTask.java:49)
at
org.eclipse.birt.report.designer.data.ui.dataset.DataSetPreviewer.preview(DataSetPreviewer.java:69)
at
org.eclipse.birt.report.designer.data.ui.dataset.ResultSetPreviewPage$5.run(ResultSetPreviewPage.java:336)
at
org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: org.eclipse.birt.data.engine.odaconsumer.OdaDataException:
Cannot get the result set metadata.
org.eclipse.birt.report.data.oda.jdbc.JDBCException: SQL statement does not return a ResultSet object. SQL error #1:ERROR: syntax error
at or near "group" Position: 236 ;
org.postgresql.util.PSQLException: ERROR: syntax error at or near "group" Position: 236 at

Syntax Error In Query with selectRaw and time diff

please advice how to correct this query
$no_of_hours = DB::Table('shifts')
->where('time_sheet_id','=', $timesheet_id->id)
->selectRaw("SELECT time(sum(TIMEDIFF( 'shift_end_time', 'shift_start_time' )))")
->get();
return $no_of_hours;
im getting following error
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT time(sum(TIMEDIFF( 'shift_end_time', 'shift_start_time' ))) from `shifts`' at line 1 (SQL: select SELECT time(sum(TIMEDIFF( 'shift_end_time', 'shift_start_time' ))) from `shifts` where `time_sheet_id` = 35)
You have a sintax error probably because you don't have to write the SELECT keyword in the selectRaw function ( the keyword is added implicity by the query builder in this case ):
->selectRaw("time(sum(TIMEDIFF( 'shift_end_time', 'shift_start_time' )))")

getting exception with SQLKorma for syntax: Failure to execute query with SQL

Any idea what is this exception trying to convey ?
I am using sqlKorma with Postgres 9.3.
I am trying to insert multiple rows at once in a table and I am getting a syntax error.
Now neither do I have a "0" anywhere in my query nor am I writing raw SQL to be messing up the syntax.
the korma docs are also not very clear.
Failure to execute query with SQL:
DO 0 :: []
PSQLException:
Message: ERROR: syntax error at or near "0"
Position: 4
SQLState: 42601
Error Code: 0
org.postgresql.util.PSQLException: ERROR: syntax error at or near "0"
Position: 4
Thats my code
(insert vendor-subsidiary-allowance
(values (vec (for [p (seq percentages)]
{:id (java.util.UUID/randomUUID)
:type "%"
:id_allowance_category (utils.uuid/from-str (p 0))
:id_vendor_subsidiary (allowance-form "vendor_sub_id")
:value (parse-number (p 1))}))))
NOTE: percentages is a dictionary with uuid strings as keys and value as some numeric string
Perhaps you want to read this to find the way to print the generated SQL to console.
You can use sql-only or dry-run macro to do this.
Print the generated SQL with sql-only or dry-run and check that the SQL is okay.