EXTRACT function SQLite support? - sqlite

In sqlite if I input such a query:
SELECT EXTRACT(YEAR FROM '2018-07-22')
I got a error. I'd like to confirm that if Sqlite support such function?

SQLite does not support EXTRACT() function.
Instead there is strftime():
SELECT strftime('%Y', '2018-07-22')

Related

Delphi FireDAC error when loading SQLite3.dll

I already downloaded the latest SQLite.dll from SQLite Download Page and try to load it using TFDPhysDriverLink.VendorLib
But when I run the app, which contains the following code:
procedure TForm1.FormCreate(Sender: TObject);
begin
FDConnection1.Close;
FDPhysSQLiteDriverLink1.Release;
FDPhysSQLiteDriverLink1.VendorLib:= 'Path\SQLite3.dll';
FDQuery1.Open('SELECT *, ROW_NUMBER() OVER() Col FROM TableName');
end;
It throws:
[FireDAC][Phys][SQLite] ERROR: near "(": syntax error
Which means that the window function ROW_NUMBER() is not recognized.
What I'm doing wrong?
How can I force FireDAC to use the latest SQLite.dll?
SQLite do not support ROW_NUMBER.
Look at the answers for this question, you'll probably find something to replace ROW_NUMBER.
If you get this error, then the SQlite3.dll was loaded just fine.
Just use the RowID field, which is always existing for any standard SQLite3 table - unless you explicitly created them with CREATE TABLE WITHOUT ROWID statement.
So I would just write:
FDQuery1.Open('SELECT *, RowID FROM TableName');
Note that if there is an explicit INTEGER PRIMARY KEY column in your table, it will in fact map the internal RowID column. Check the SQLite3 documentation for how this works.

SQL lite in Azure CAST(date AS datetime)

I want to fix my date column from this: 2009-01-09T00:00:00
To this: 2009-01-09
Im running it on SQL lite in Azure ML
I tried this code:
select CAST(date AS datetime)
from t1;
But all it returns is 2009
I also tried this code:
select CAST(date AS date)
from t1;
But with the same result : 2009 only
I would prefer to use CAST and not CONVERT (or similar)
What is the simplest way to accomplish this?
SQLite3 does not have a DATETIME type, so it is interpreted as NUMERIC (please see https://sqlite.org/datatype3.html for an explanation), using CAST on your string will result as you have seen in its being scanned as an integer. To get what you want, use the substr(X,Y,Z) function (see https://sqlite.org/lang_corefunc.html#substr ).

SQLite3 explain query plan (raspberry PI)

My development os is Linux(raspberry pi).
I installed sqlite3 and it is latest version.
explain query plan returns value
for example
sqlite> explain query plan select * from test_table
0|0|0|SCAN TABLE test_table (~100000 rows)
but my result is
:
sqlite> explain query plan select * from test_table
0|0|0|SCAN TABLE test_table
(~100000 rows) is not shown.
what is problem? Thanks
The documentation says:
Warning: The data returned by the EXPLAIN QUERY PLAN command is intended for interactive debugging only. The output format may change between SQLite releases.
You are using another SQLite release, and the output format indeed changed.

Using Limit and offset in Sqlite update statmet

update table set column_name limit 3 offset 2;
The above query is not working.
Throws error
sql error: syntax error near 'limit'.
An UPDATE statement expects a new value after the column_name, like this:
update thetable set column_name = 'some new value'
Furthermore, the documentation mentions that you need to have compiled SQLite with the SQLITE_ENABLE_UPDATE_DELETE_LIMIT option, which is not enabled by default.
Sqlite does not allow the use of LIMIT and OFFSET statements like in MYSQL. You will have to use a nested query to workaround it . Or use two queries.

convert column data to xml format; query fails because all columns types are currently not supported

I am trying to convert column data to xml format, but I get this error message:
The query fails because all columns types are currently not supported.
CREATE TABLE EMP(NAME VARCHAR2(10 BYTE))
INSERT INTO EMP VALUES ('C');
INSERT INTO EMP VALUES ('A');
INSERT INTO EMP VALUES ('T');
SELECT xmlelement("NAME",NAME) FROM EMP;
I am using:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
SQLTools 1.5.0 Beta build 9 as EDITOR
Why is this error arising??? What is the solution for this?
I've found the answer:
select dbms_xmlquery.getxml('select * from EMP') from dual;
This is more of a workaround and not a solution.
I was having the same problems as sam - also running a SELECT xmlelement statement, also using SQLTools. One difference is that I was running Oracle DB version 11.2.0.2.0.
I found that if I ran the statement in SQLPlus, it was able to display the result.
SQL> SELECT XMLELEMENT("name",ename) FROM scott.emp WHERE ROWNUM < 3;
XMLELEMENT("NAME",ENAME)
--------------------------------------------------------------------------------
<name>SMITH</name>
<name>ALLEN</name>
If I ran the statement in SQL Developer, it tried to display the results, but only showed (XMLTYPE).

Resources