TDengine restful API produce unexpected results in distinct SQL - distinct

Try using TDengine v2.3.3.0 with restful API.
Insert some data like this with binary data type. Insert data into some sub tables with different lengths of value. Then do distinct query of the column.
create stable stb1 (ts timestamp, name binary(10)) tags(n int);
insert into tb1 using stb1 tags(1) values(now, 'a');
insert into tb2 using stb1 tags(2) values(now, 'bc');
insert into tb3 using stb1 tags(3) values(now, 'def');
insert into tb4 using stb1 tags(4) values(now, 'ghij');
insert into tb5 using stb1 tags(5) values(now, 'klmno');
insert into tb6 using stb1 tags(6) values(now, 'pqrs');
insert into tb7 using stb1 tags(7) values(now, 'tuv');
insert into tb8 using stb1 tags(8) values(now, 'wx');
insert into tb9 using stb1 tags(9) values(now, 'y');
Query data with curl:
curl -u root:taosdata -d 'select distinct(name) from test01.stb1' localhost:6041/rest/sql | \
jq '.data[][0]' -r |sort
The result is
a
bc
def
ghij
klmno
pqrso
tuvso
wxvso
yxvso

Sorry for the bad experience, this bug will be fixed in next version of TDengine. You could build and replace taosadapter with the github version currently.

Related

Select into multilevel type in Oracle

I am trying to find out if there is a way to bulk collect into a multi-level type in Oracle. The example below should help in explaining the concept of what I am trying to do.
There is a source table with a denormalised list of counties and towns:
create table county_town (county varchar2(20), town varchar2(20));
insert into county_town values ('Surrey', 'Dorking');
insert into county_town values ('Surrey', 'Woking');
insert into county_town values ('Surrey', 'Guildford');
insert into county_town values ('Oxfordshire', 'Thame');
insert into county_town values ('Oxfordshire', 'Abingdon');
What I want to do is load this into a multilevel type that looks like this:
create type towns_typ as table of varchar2(20);
create type counties_typ as object (country varchar2(20), towns towns_type);
create type nt_counties_typ as table of counties_typ;
l_county_data nt_counties_typ
Is there some way that I can write a SELECT statement to BULK collect this data into l_county_data from the table county_town ? If BULK COLLECT cant be used is there another way to do this simply?
Yes, like here:
declare
l_county_data nt_counties_typ;
begin
select counties_typ(county, cast(collect(town) as towns_typ))
bulk collect into l_county_data
from county_town
group by county;
dbms_output.put_line(l_county_data(2).county);
end;
dbfiddle

Insert a record having timestamp(6) field from Oracle to Postgresql via dblink bug?, lose timestamp precision?

I am in trouble while inserting a new record to postgresql from oracle database server. After insert a new record into postgresql, I lose precision of timestamp fields, all digits which refers to microsecond had been lose. Here is my sample code:
declare
v_date timestamp(6):=to_timestamp('2013-06-04 12:03:01.123456','YYYY-MM-DD HH24:MI:SS.FF6');
begin
dbms_output.put_line (v_date);
insert into "public"."DAS_ITEM"#PG_LINK
("DOCKID","CANDY_ITM_NBR","MODIFIED_ON") VALUES (1,3, v_date);
commit;
end;
After running the pl/sql, I would like to query the data from postgres directly
select "DOCKID","CANDY_ITM_NBR", to_char("MODIFIED_ON", 'YYYY-MM-DD HH24:MI:SS.US') from "DAS_ITEM";
and here is the result:
DOCKID | CANDY_ITM_NBR | MODIFIED_ON
-----------+---------------+---------------------------
1 | 3 | 2013-06-04 12:03:01.000000
Currently, the value of MODIFIED_ON field is '2013-06-04 12:03:01.000000', I expect the value of MODIFIED_ON was 2013-06-04 12:03:01.123456
Please help me, I am in trouble for 36 hours.

After insert in one table, insert into another table in Oracle APEX

What I would like to do is;
after I insert some data into table1, I would like some of that data automatically inserted into table2, such as the primary key from table1 inserted into table2 as a foreign key.
Is this done using a trigger.
Not sure where to start looking first.
Cheers
Brian
Yes you can do that through trigger. You can do it like this:
CREATE OR REPLACE TRIGGER my_trigger
before INSERT ON table1
REFERENCING NEW AS NEW
for each row
BEGIN
insert into table2(fk_column,column1) values(:new.pk_column_of_table1,'value1');
END;
you can create a trigger as #vance said and you can use returning into clause if you are populating some of the columns dynamically
INSERT INTO t1 VALUES (t1_seq.nextval, 'FOUR')
RETURNING id INTO l_id;
have a look here

Oracle: insert from type table

i want to insert from a type of table into a table.
Is there a way to do this with bulk? And can I change the type table content a little?
Just like here, but the other way around:
How to insert data into a PL/SQL table type rather than PL/SQL table?
Assuming that you have something like
CREATE TYPE my_nested_table_type
AS TABLE OF <<something>>;
DECLARE
l_nt my_nested_table_type;
BEGIN
<<something that populates l_nt>>
then the way to do a bulk insert of the data from the collection into a heap-organized table would be to use a FORALL
FORALL i in 1..l_nt.count
INSERT INTO some_table( <<list of columns>> )
VALUES( l_nt(i).col1, l_nt(i).col2, ... , l_nt(i).colN );

Insert content of table variable into table

I have the following table, two types based on it, and a function that reads from this table:
CREATE TABLE myTable (
ID RAW(16) NULL,
NAME NVARCHAR2(200) NULL,
ENTITYID RAW(16) NOT NULL
);
CREATE TYPE myRowType AS OBJECT (
NAME NVARCHAR2(200),
ENTITYID RAW(16)
);
CREATE TYPE myTableType IS TABLE OF myRowType;
CREATE FUNCTION myFunction(...) RETURN myTableType ...
As you can see, the type myRowType is similar to myTable, but not exactly.
My goal is to insert rows into myTable based on the results of myFunction.
The naive approach would be to just write:
INSERT INTO myTable(ID, NAME, ENTITYID)
SELECT sys_guid(), NAME, ENTITYID
FROM TABLE(myFunction(...));
But since myFunction reads from myTable, this leads to the following error:
ORA-04091: table myTable is mutating, trigger/function may not see it
So I have to split the myFunction call from the insert statement. I tried it like this:
DECLARE
tbl myTableType;
BEGIN
SELECT myRowType(x.NAME, x.ENTITYID)
BULK COLLECT INTO tbl
FROM TABLE(myFunction(...)) x;
INSERT INTO myTable
(ID, NAME, ENTITYID)
SELECT sys_guid(), x.NAME, x.ENTITYID
FROM tbl x;
END;
But here, Oracle doesn't seem to understand the FROM tbl clause. It shows the error
ORA-00942: table or view does not exist
How can I insert the rows in tbl into myTable?
Since you can't use a locally defined nested table as an argument for TABLE function, maybe you would consider using the FORALL bulk insert? I see you are using Oracle 11g, so you will be able to access fields of myRowType. You would then replace your INSERT from your PL/SQL block with this:
FORALL v_i IN tbl.FIRST..tbl.LAST
INSERT INTO myTable VALUES (sys_guid(), tbl(v_i).name, tbl(v_i).entityid);
I recommend this great article by Tim Hall: BULK COLLECT & FORALL

Resources