postgresql : **ERROR: path element at position 1 is not an integer:** - jsonb

I am trying to update a field value in jsonb column with text value present in another column but getting some syntax errors; not getting any solution.
'[
{
"Edgeid":10,
"Weight":100,
"Active":1,
"OutgoingVertexid":"",
"IncomingVertexid":"G",
"EdgeColor":"Black"
}
]
'
so used below code by putting all values OutgoingVertexid & IncomingVertexid value in temp table.
UPDATE temp_table
SET
owner_property = CASE
WHEN owner_outgoing_edge IS NOT NULL
THEN jsonb_set(owner_property, '{OutgoingVertexid}', '""')
ELSE NULL END;
jsonb_set(owner_property, '{OutgoingVertexid}', ''||owner_incoming_edge::jsonb||'')
END;
but getting below error:
ERROR: path element at position 1 is not an integer: "OutgoingVertexid"
Thanks in Advance

Related

operator.itemgetter(*item) giving error TypeError: '<' not supported between instances of 'NoneType' and 'int'

I am using a recursive function for Grouping data list which I am getting by executing database query and the below function worked fine. But since yesterday it started throwing error as below:
in _group_data data_list.sort(key=itemgetter(*filter_key))
TypeError: '<' not supported between instances of 'NoneType' and 'int'
def _group_data(data_list, key_list, previous_key=[]):
"""
:param data_list: A list of dictionary got from executing sql query.
:param key_list: Group by list of keys.
:param previous_key: The earlier key to do grouping at the root level. Default is an empty list.
:return: Grouped Data list.
"""
# Base case
if len(key_list) == 1:
filter_key = key_list[0]
data_list.sort(key=itemgetter(*filter_key))
dl = list()
for _, group in groupby(data_list, key=itemgetter(*filter_key)):
d_dict = {'details': []}
for g in group:
if previous_key is not None:
d_dict['details'].append(
{key: value for key, value in g.items() if key not in (filter_key + previous_key)}
)
d_dict.update({key: value for key, value in g.items() if key in filter_key})
else:
d_dict['details'].append({key: value for key, value in g.items() if key not in filter_key})
d_dict.update({key: value for key, value in g.items() if key in filter_key})
dl.append(d_dict)
return dl
# Recursive block
else:
filter_key = key_list[0]
dl = list()
p_key = previous_key + filter_key
data_list.sort(key=itemgetter(*filter_key)) #getting error here
for _, group in groupby(data_list, key=itemgetter(*filter_key)):
group_list = list(group)
print('key_list[1:] ',key_list[1:])
print('p_key ',p_key)
d_list = _group_data(group_list, key_list[1:], p_key)
p_dict = {key: value for key, value in group_list[0].items() if key in filter_key}
p_dict['details'] = d_list
dl.append(p_dict)
return dl
I am trying to Identify the problem but not getting any clue, Also tried few things from the google search but nothing helped for example sorted() but got the same error. Thanks in advance for the help.
Issue was resolved. I was getting data as null for a key, but it was supposed to be integer that's why it was throwing error. so, from the dB side value of that key is set to 0 as a default.

Setting Linq2Db to read and update with CHAR type and NOT NULL constraint in Oracle

Reading value of fixed CHAR string from table, using Linq2db Oracle provider:
CREATE TABLE mytable
(pk NUMBER(15,0) NOT NULL,
fixed_data CHAR(20) DEFAULT ' ' NOT NULL)
Although in database, length of FIXED_DATA filed is 20,
SELECT LENGTH(fixed_data) FROM mytable WHERE pk = 1
-- result is 20
When same field is read using Linq2Db, value gets truncated to empty string:
var row = (from row in database.mytable where row.pk == 1 select row).ToList()[0];
Console.WriteLine(row.fixed_data.Length);
// result is zero
This causes problem when record is updated using Linq2Db, Oracle converts empty string to NULL, and UPDATE fails:
database.Update(row);
// Oracle.ManagedDataAccess.Client.OracleException: 'ORA-01407: cannot update ("MYSCHEMA"."MYTABLE"."FIXED_DATA") to NULL
Is there any setting in Linq2Db for read->update cycle to work with CHAR type and NOT NULL constraint?
Found a solution, thanks to source code openly available. By default, Linq2Db calls expression IDataReader.GetString(int).TrimEnd(' ') on every CHAR and NCHAR column. However this can be easily customized, by implementing custom provider, which overrides field value retrieval expression, with one that does not trim:
class MyOracleProvider : OracleDataProvider
{
public MyOracleProvider(string name)
: base(name)
{
// original is SetCharField("Char", (r,i) => r.GetString(i).TrimEnd(' '));
SetCharField("Char", (r, i) => r.GetString(i));
// original is SetCharField("NChar", (r,i) => r.GetString(i).TrimEnd(' '));
SetCharField("NChar", (r, i) => r.GetString(i));
}
}

How to replace value of column in a row with other columns in same row

How to replace value of column in a row with other columns in same row below are the sample db data and output which is required any help would be appreciated.
Data in DB:
I tried using if else but not able to solve it below is the sample if else code
if ((#adrln1 is null) and (#adrln2 is not null or #adrln3 is not null or #adrstc is not null or #adrpsz is not null or #ctry_name is not null))
{
publish data
where adrnam = #adrnam
and adrln1 = #adrln2
and adrln2 = #adrln3
and adrln3 = #adrstc
and adrstc = #adrpsz
and adrpsz = #ctry_name
and ctry_name = ''
}
Required Result:

what's the syntax error in these sas codes

data work.totalsales;
set work.monthlysales(keep = year product sales);
retain monthsales {12};
array monthsales {12};
do i = 1 to 12;
monthsales{i} = sales;
end;
count + 1;
monthsales{count} = sales;
run;
I submit these codes. But it appears to have syntax problems. But where?
Syntax issue is the array style name in the retain statement.
Runtime error possible because count is not initialized. If there are more than 12 records in "monthlysales" you will get an "array out of bounds" error on the 13th record.

Handling DataTable Column Name Mismatch Exception

i feeding my Data table from excel sheet upload,i face the problem when i look for a particular columns, ironically i don't know the position of column ,That can be anywhere or may be not present
so i cant Use indexing,when i go with column name then white spaces causing the problem
i assume the i know the index of Column but how can i handle the whitespaces
so far what i tried
Code:
if (ds.Tables[0].Columns[3].Caption.Replace(" ", "").Equals("XXXX"))
{
var ds = from r in ds.Tables[0].AsEnumerable() select new { Fname=r.Field<String>("XX XX") , Lname=r.Field<string>(" Yy YY Y ") };
ds.ToList();
}
Do i need to care About the case sensitiveness in Column Name ?
how can i find the Column index if it matched with a given String ?
You can find the column like:
DataColumn yourColumn = ds.Tables[0].Columns.Cast<DataColumn>()
.Where(r => r.Caption.Trim().Equals("XXXX",StringComparison.InvariantCultureIgnoreCase))
.FirstOrDefault();

Resources