I have a column with data type Array(String) in spanner. How can I append value to an array for update queries
I'm able to update the values using this command
update CarTable set models = ["BMW","HONDA"] WHERE year = "2020"
But the problem with this update is it overrides the previous values. I want to append these values to the ones that are already present. Is there any command that takes care of this requirement?
You can use the ARRAY_CONCAT function for that:
update CarTable set models = ARRAY_CONCAT(models, ["BMW","HONDA"]) WHERE year = "2020"
Related
This is my table:
I want to change the TargetCondition column to 'TRUE' when the ICD9CODE column contains a particular range (like between 250 and 250.93).
Please help me do it. Thanks
This is the code here:
update demo.fea_02 set TargetCondition = TRUE where ICD9Code like between '%250%' and '%250.93%'
got the error:
Syntax error: Unexpected keyword BETWEEN at [6:17]
This answers the original version of the question.
You would use update:
update mytable
set targetcondition = 'TRUE'
where icd9code like '%value%';
I have a table T with a column J of type json, and one of it's row contains value
{'SELECTION':'A'}
I want to change it to
{'selection':'A'}
i.e change the key of the JSON.
Any one has experience? I am not able to find any relevant resource.
Thanks to #Sebastian, I solved it using the documentation https://www.postgresql.org/docs/current/functions-json.html
update T set J = '{"selection":"A"}' where J::jsonb #> '{"SELECTION":"A"}'::jsonb
Another query that will do same
update T set J = '{"selection":"A"}' where J::json->>'SELECTION'='A'
I've just started using microsoft access so I don't really know how to solve this. I would like to use an update query to add a value from a form to a value on a table.
I originally used the SUM expression which gave me an error saying it was an aggregate function.
I also tried to add the two values together (e.g [field1] + [field2]) which as a result gave me a value with both numbers together instead of adding them together.
The following is the SQL I'm using:
UPDATE Votes
SET Votes.NumVotes = [Votes]![NumVotes]+[Forms]![frmVote]![txtnumvotes]
WHERE (((Votes.ActID) = [Forms]![frmVote]![combacts])
AND ((Votes.RoundNum) = [Forms]![frmVote]![combrndnum]))
I want to add a value [txtnumvotes] a form to a field [NumVotes] from the table [Votes].
Could someone please help me?
You can specify the expected data type with parameters:
PARAMETERS
[Forms]![frmVote]![txtnumvotes] Short,
[Forms]![frmVote]![combacts] Long,
[Forms]![frmVote]![combrndnum] Long;
UPDATE
Votes
SET
Votes.NumVotes = [Votes]![NumVotes]+[Forms]![frmVote]![txtnumvotes]
WHERE
(((Votes.ActID) = [Forms]![frmVote]![combacts])
AND
((Votes.RoundNum) = [Forms]![frmVote]![combrndnum]))
Without the specification, Access has to guess, and that sometimes fails.
I have a database with a json field which has multiple parts including one called tags, there are other entries as below but I want to return only the fields with "{"tags":{"+good":true}}".
"{"tags":{"+good":true}}"
"{"has_temps":false,"tags":{"+good":true}}"
"{"tags":{"+good":true}}"
"{"has_temps":false,"too_long":true,"too_long_as_of":"2016-02-12T12:28:28.238+00:00","tags":{"+good":true}}"
I can get part of the way there with this statement in my where clause trips.metadata->'tags'->>'+good' = 'true' but that returns all instances where tags are good and true including all entries above. I want to return entries with the specific statement "{"tags":{"+good":true}}" only. So taking out the two entries that begin has_temps.
Any thoughts on how to do this?
With jsonb column the solution is obvious:
with trips(metadata) as (
values
('{"tags":{"+good":true}}'::jsonb),
('{"has_temps":false,"tags":{"+good":true}}'),
('{"tags":{"+good":true}}'),
('{"has_temps":false,"too_long":true,"too_long_as_of":"2016-02-12T12:28:28.238+00:00","tags":{"+good":true}}')
)
select *
from trips
where metadata = '{"tags":{"+good":true}}';
metadata
-------------------------
{"tags":{"+good":true}}
{"tags":{"+good":true}}
(2 rows)
If the column's type is json then you should cast it to jsonb:
...
where metadata::jsonb = '{"tags":{"+good":true}}';
If I get you right, you can check text value of the "tags" key, like here:
select true
where '{"has_temps":false,"too_long":true,"too_long_as_of":"2016-02-12T12:28:28.238+00:00","tags":{"+good":true}}'::json->>'tags'
= '{"+good":true}'
I have a table that I want to update a column in the whole thing. I have this for the concatenation.
(COALESCE(f1,'')+';'+ COALESCE(f2,'')+';'+ COALESCE(f3,''))
Well when I insert this into my column it adds new columns and update just fails. Is there a way to update a value inside MS SQL and use it to change a value?
Thanks
update dbo.tblGeoTable (CombinedEmail)
select (COALESCE(f1,'')+';'+ COALESCE(f2,'')+';'+ COALESCE(f3,''))
from dbo.tblGeoTable
Here is the data
F1 = f1email#email.com
F2 = f2email#email.com
F3 = f3email#email.com
CombinedEmail = f1+f2+f3, but I need the ; in there to seperate them and I need it replaced in the current row that its in.
If I understand correctly what you want try this
UPDATE tblGeoTable
SET CombinedEmail = COALESCE(f1,'')+';'+ COALESCE(f2,'')+';'+ COALESCE(f3,'')
Here is sqlfiddle example
EDIT:
If you want to add instead of replace to the values in CombinedEmail column you can do
UPDATE tblGeoTable
SET CombinedEmail = COALESCE(CombinedEmail,'') + ';' + COALESCE(f1,'')+';'+ COALESCE(f2,'')+';'+ COALESCE(f3,'')