In SQLite , How would you store the information like this:
id name groups
1 xyz one,two
2 abc one
3 lmn two,three
The groups column may multiple entries. How can we store like that?
The main thing is the multiple values are should be appended.
I'm not sure I understand it correctly but why not store it as delimited string? Something like string1;string2;string3..or use comma instead of semi-colon like you already posted.
Just fetch the row, append the data followed by your delimiter and update the record. When you need the individual entries, just split the string using your delimiter.
Related
Want to loop through a comma separated text file.
For ex:
mytext <- 3,24,25,276,2,87678,20-07-2022,1,5
From this mytext I would like to loop through like below :
for (i in 1:length(mytext)) {
print(mytext[[i]])
}
I need to display like
3
24
25
276
2
87678
20-07.2021
1
5
Actually I need to set every value as an individual variable, like :
variable1:3
variable2:24
variable3:25
variable4:276
variable5:2
variable6:87678
variable7:20-07.2021
variable8:1
variable9:5
(my project is retrieve data from text file and then having database validations in R before entering records to database.)
Could anyone help me out? Thanks in advance.
Split your string:
strsplit(mytext, ",")[[1]]
I'm using the following code to get a user's recovery_token and store it in a variable:
Connect To Database psycopg2 ${DB_NAME}
... ${DB_USER_NAME}
... ${DB_USER_PASSWORD}
... ${DB_HOST}
... ${DB_PORT}
${RECOVERY_TOKEN}= Query select recovery_token FROM public."system_user" where document_number like '57136570514'
Looking at the log, the recovery_token is being saved as follows:
${RECOVERY_TOKEN} = [('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImU3ZGM4MmNjLTliMGQtNDc3OC1hMzM0LWEyNjM4MDU1Mzk1MSIsImlhdCI6MTYyMzE5NjM4NSwiZXhwIjoxNjIzMTk2NDQ1fQ.mdsrQlgaWUol02tZO8dXlL3KEwY6kqwj5T7gfRDYVfU',)]
But I need what is saved in the variable ${RECOVERY_TOKEN} to be just the token, without the special characters [('',)]
${RECOVERY_TOKEN} = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImU3ZGM4MmNjLTliMGQtNDc3OC1hMzM0LWEyNjM4MDU1Mzk1MSIsImlhdCI6MTYyMzE5NjM4NSwiZXhwIjoxNjIzMTk2NDQ1fQ.mdsrQlgaWUol02tZO8dXlL3KEwY6kqwj5T7gfRDYVfU
Is there any way I can remove the special characters?
Thanks in advance!!
The returned value is a list of tuples, a two-dimensional matrix (e.g. a table); if you have queried for 3 columns for example, the inner tuple would have 3 members. And if there were 5 records that match it, the list would have 5 tuples in it.
Thus to get the value you are after, get it from the matrix by its indexes (which are 0-based, e.g. the first element is with index "0"):
${RECOVERY_TOKEN}= Set Variable ${RECOVERY_TOKEN[0][0]}
I Have multiple records in table like below. Each record holds mutiple entries separated by #.
record1 - 123.45.56:ABCD:789:E # 1011.1213.1415:FGHI:1617:J #
record2 - 123.45.56:ABCD:1617:E # 1011.1213.1415:FGHI:12345:J #
I need to pass an argument to a different project/service which builds an sql query and send the output to me.
Now if I send an argument like below, it gives me wrong output
123.45.56:*:1617
This recognizes both record1 and record 2 as proper output because of wildcard char. But as per my requirement only record2 is proper as record1 has 123.45.56 in one entry and 1617 in a different entry.
Is there a way to construct an expression that says the like condition to ignore such invalid entries.
Please note that I cant change the query as I am not constructing it. The only way for me is to tweak the expression that I can send as argument.
You need to restrict the pattern you match to be specic enough such that it only matches the first record and not the second one.
You can try:
SELECT *
FROM yourTable
WHERE col LIKE '123.45.56:' AND col LIKE '1617:J #'
I have a file with 3 column where one of the column will consist of an "array" with delimiter as say "," . I will need to link the text inside the array to form something like a linked list. After which, it will be linked to the other 2 column.
For example:
Column 1 (Text): A
Column 2 (Array of text): B1, B2, B3, B4
Column 3 (Text): C
I will need something like A->B1->B2->B3->B4->C to be visualise in Neo4j.
I need help in forming the "LOAD CSV..." query. Appreciate any help offered!
You can use split for extracting each element of the desired array
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM
'file://directory/file.csv' AS line
with SPLIT(line.columnName,',') as arrayColumn
now you can use each data of the arrayColumn like
arrayColumn[0], arrayColumn[1]
then you can create relationships or node
MERGE (v:LabelName {name:arrayColumn[0]})-[:relations]->(v:LabelName {name:arrayColumn[1]})
Hope this helps ...
I have a table with rows where I would like to replace the content in a column as follows:
text1.... word1...text2
I only know the word1, and I would like to delete word1 and the rest of the string, text2 in the example.
If you think about the problem as keeping everything up to word1 you can see that it can be solved with substr and instr, something along the lines of
UPDATE table SET column = substr(column, 1, instr(column, 'word1')-1);
Note that substr() and instr() are SQLite specific, other engines may have similar functions with different names.