Invalid map literal with Cassandra Query - collections

I'm trying to do this query :
insert into test (id, identifiers) values('1', {'id':'test', 'id_bin':{'\x3500000000000050a0'}, 'oidcatref':'1', 'otype_bin':'1', 'id_qaul':'test', 'id_flag':'1'});
That's my identifier type :
create type identifier(id text, id_bin list<blob>, oidcatref bigint, otype_bin int, id_qaul text, id_flag smallint);
And my table structure :
create table test (id int primary key, identifiers frozen<identifier>);
I really don't know what is wrong, thanks for your help

Only enclose string value with single quote. And for UDT field remove quote from field name
insert into test (id, identifiers) values
(
1,
{
id :'test',
id_bin : [0x3500000000000050a0],
oidcatref : 1,
otype_bin : 1,
id_qaul : 'test',
id_flag : 1
}
);

Related

PL/SQL Changing datatype Big int To Varchar(string) facing error BIGINT not in range [-9223372036854775808]

I am trying to change existing attribute values whose datatype is big int by adding new attribute as datatype varchar
e.g : Existing attribute name is supplier_id (datatype is big int)
New Attribute name is supplier_id_1 (datatype is varchar)
Values present in attribute is 5 characters.
e.g : 370430 (big int ) ---> need to change into varchar "370430".
I'm facing Error message
BIGINT not in range [-9223372036854775808
Help me to solve this .

creating after delete trigger with two different database using database link

Created two tables in two different database(TestDb1 and TestDb2) in the same server.I wrote after delete trigger on "Error_Master" table`.if i delete record in "ERROR_MASTER" table which is in TestDB1 that trigger insert records in "ERROR_MASTER_LOG" table which exists in TestDb2.
My dblink->dblink('dbname=TestDb2 port=5432 host=192.168.0.48 user=postgres password=soft123')
DB->TestDb1
CREATE TABLE public."ERROR_MASTER"
(
"MARKERID" integer NOT NULL,
"FILENAME" character varying,
"RECNO" integer,
"ERRORCODE" character varying,
"USERID" character varying,
"ID" integer NOT NULL,
CONSTRAINT "ERR_MASTER_pkey" PRIMARY KEY ("ID")
)
WITH (
OIDS=FALSE
);
DB->TestDb2
CREATE TABLE public."ERROR_MASTER_LOG"
(
"MARKERID" integer NOT NULL,
"FILENAME" character varying,
"RECNO" integer,
"ERRORCODE" character varying,
"USERID" character varying,
"ID" integer NOT NULL,
CONSTRAINT "ERR_MASTER_Log_pkey" PRIMARY KEY ("ID"),
"Machine_IP" character varying,
"DELETED_AT" timestamp
)
WITH (
OIDS=FALSE
);
ALTER TABLE public."ERROR_MASTER_LOG"
OWNER TO postgres;
GRANT ALL ON TABLE public."ERROR_MASTER_LOG" TO postgres;
CREATE INDEX "IDX_ERROR_MASTER_LOG_MARKERID_RECNO"
ON public."ERROR_MASTER_LOG"
USING btree
("MARKERID" COLLATE pg_catalog."default", "RECNO" COLLATE pg_catalog."default", round("X1"::numeric, 2));
i tried below trigger in TestDb1 for inserting record in a table which exists in another database TestDb2 using dblink. It shows schema "old" does not exist.Please help.
CREATE OR REPLACE FUNCTION mdp_error_master_after_delete()
RETURNS trigger AS
$BODY$
BEGIN
perform dblink_connect('host=localhost user=postgres password=postgres dbname=TestDB2');
perform dblink_exec('INSERT INTO "ERROR_MASTER_LOG"("MARKERID","ID")
values('||OLD."MARKERID"||','||OLD."ID"')');
perform dblink_disconnect();
RETURN OLD;
EXCEPTION WHEN OTHERS THEN
RAISE NOTICE 'insert_new_sessions SQL ERROR: %', SQLERRM;
RETURN NULL;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION mdp_error_master_after_delete()
OWNER TO postgres;
CREATE TRIGGER ERROR_MASTER_CHANGES
AFTER DELETE
ON "ERROR_MASTER"
FOR EACH ROW
EXECUTE PROCEDURE mdp_error_master_after_delete()

How to concat a json arrays objects values in SQLite

As part of a larger select query I need to extract the values from an json array's objects as a comma separated string.
I have managed to get the json array out of the json object:
SELECT * FROM (SELECT json_extract(Site.Login, '$.Uris') FROM Site);
Second variant giving the same result:
SELECT value FROM json_each(Site.Login), Site WHERE json_each.key = 'Uris';
A test with a single row giving the wanted result:
SELECT group_concat(json_extract(value, '$.Uri')) as login_uri FROM json_each('[{"Uri":"https://cnn.com"},{"Uri":"https://bbc.com"},{"Uri":"https://reuters.com"}]');
I am lost in the matrix. I have tried to various ways of combining the query code above, but I can not make any headway.
An example of a Site.Login cell. The number of Uri objects can be from 0 to infinite.
{
"Uris": [
{"Uri":"https://cnn.com"},
{"Uri":"https://bbc.com"},
{"Uri":"https://reuters.com"}
],
"Username": "ghhhhhhhhhhhhhfgggggggggggggggg",
"Password": "hgfhfghfghfgh",
"PasswordRevisionDate": "2019-01-07T21:51:42.65Z",
"Totp": "gffffffffffffffffffffffhhhhhhhhhhhhhhhfghghgfh",
"Name": "hgfhfghfghfghfgh",
"PasswordHistory": [
{
"Password": "ghfghfghfghfghfg",
"LastUsedDate": "2019-01-07T21:51:42.65Z"
}
]
}
The full layout of the Site table:
CREATE TABLE "Site" (
"Id" varchar primary key not null ,
"FolderId" varchar ,
"UserId" varchar ,
"OrganizationId" varchar ,
"Name" varchar ,
"Notes" varchar ,
"Fields" varchar ,
"PasswordHistory" varchar ,
"Login" varchar ,
"Card" varchar ,
"Identity" varchar ,
"SecureNote" varchar ,
"Favorite" integer ,
"Edit" integer ,
"OrganizationUseTotp" integer ,
"RevisionDateTime" bigint ,
"Type" integer ,
"Data" varchar )
The select query should return a column named login_uri containing the extracted json array objects values as a concatenated string:
https://cnn.com,https://bbc.com,https://reuters.com
You're very close!
SELECT group_concat(json_extract(j.value, '$.Uri')) AS login_uri
FROM site AS s
JOIN json_each(json_extract(s.login, '$.Uris')) AS j
gives
login_uri
---------------------------------------------------
https://cnn.com,https://bbc.com,https://reuters.com
If you want each row in the table to give a result row, instead of all uris in the entire table being concatenated together into a single string, add a GROUP BY s.id to the end.

SQL Error: ORA-00904: : invalid identifier in line 4

I was working in sql command line and got this error ORA-00904 when i queried to create a table
I tried various inputs and got the same error in line 4.
Help me out.
If you create a table
Then this would work :
CREATE TABLE DATA
(
ID INT NOT NULL,
NAME VARCHAR2(10) NOT NULL
);
But this would raise an ORA-00904 :
CREATE TABLE DATA
(
ID INT NOT NULL,
NAME VARCHAR2(10) NOT NULL,
);
The difference?
After that last comma, something more is expected.
Yet, all it finds is a round bracket.
Hence, the error.

How to autogenerate the username with specific string?

I am using asp.net2008 and MY SQL.
I want to auto-generate the value for the field username with the format as
"SISI001", "SISI002",
etc. in SQL whenever the new record is going to inserted.
How can i do it?
What can be the SQL query ?
Thanks.
Add a column with auto increment integer data type
Then get the maximum value of that column in the table using "Max()" function and assign the value to a integer variable (let the variable be 'x').
After that
string userid = "SISI";
x=x+1;
string count = new string('0',6-x.ToString().length);
userid=userid+count+x.ToString();
Use userid as your username
Hope It Helps. Good Luck.
PLAN A>
You need to keep a table (keys) that contains the last numeric ID generated for various entities. This case the entity is "user". So the table will contain two cols viz. entity varchar(100) and lastid int.
You can then have a function written that will receive the entity name and return the incremented ID. Use this ID concatenated with the string component "SISI" to be passed to MySQL for insertion to the database.
Following is the MySQL Table tblkeys:
CREATE TABLE `tblkeys` (
`entity` varchar(100) NOT NULL,
`lastid` int(11) NOT NULL,
PRIMARY KEY (`entity`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
The MySQL Function:
DELIMITER $$
CREATE FUNCTION `getkey`( ps_entity VARCHAR(100)) RETURNS INT(11)
BEGIN
DECLARE ll_lastid INT;
UPDATE tblkeys SET lastid = lastid+1 WHERE tblkeys.entity = ps_entity;
SELECT tblkeys.lastid INTO ll_lastid FROM tblkeys WHERE tblkeys.entity = ps_entity;
RETURN ll_lastid;
END$$
DELIMITER ;
The sample function call:
SELECT getkey('user')
Sample Insert command:
insert into users(username, password) values ('SISI'+getkey('user'), '$password')
Plan B>
This way the ID will be a bit larger but will not require any extra table. Use the following SQL to get a new unique ID:
SELECT ROUND(NOW() + 0)
You can pass it as part of the insert command and concatenate it with the string component of "SISI".
I am not an asp.net developer but i can help you
You can do something like this...
create a sequence in your mysql database as-
CREATE SEQUENCE "Database_name"."SEQUENCE1" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 001 START WITH 21 CACHE 20 NOORDER NOCYCLE ;
and then while inserting use this query-----
insert into testing (userName) values(concat('SISI', sequence1.nextval))
may it help you in your doubt...
Try this:
CREATE TABLE Users (
IDs int NOT NULL IDENTITY (1, 1),
USERNAME AS 'SISI' + RIGHT('000000000' + CAST(IDs as varchar(10)), 4), --//getting uniqueness of IDs field
Address varchar(150)
)
(not tested)

Resources