Gremlin: Find duplicates of a vertex by 'name' property and execute as list of 'id' - orientdb

The below code groups all userProfileTemplates by name, finds where there are duplicates and then projects the "name" of the userProfileTemplate where the count of name is > 1. I want to find duplicates by "name", but I want to execute it as a list of "Id" (Id is a property of userProfileTemplate). Any suggestions?
g.V().hasLabel('userProfileTemplate').group().by(values('name').fold()).unfold().filter(select(values).count(local).is(gt(1))).select(keys)unfold().project('Duplicate User Profiles')
Update: The below is executing a column named "value" with the multiple 'id' that correspond to the duplicate 'name', separated by commas in betweeen brackts.
g.V().hasLabel('userProfileTemplate').group().by('name').by('id').unfold().filter(select(values).count(local).is(gt(1))).select(values)
I would like to also execute a column that shows the corresponding 'name' for all duplicate ids.

It's almost what you already have, you only need to add another by().
g.V().hasLabel('userProfileTemplate').
group().
by('name').
by('Id').
unfold().
filter(select(values).count(local).is(gt(1))).
select(keys)

Related

replicate subquery in PowerBI

I have two tables:
The merge is on the field name value of the JLE_LineTypeCategory matching the Type and Line Type columns on JobLedgerEntry. In SQL, I would do something like this:
SELECT optiontext
FROM metadataTable md
WHERE TableName='JobLedgerEntry'
AND FieldName='LineType'
AND md.OptionInteger=JobLedgerEntry.[Type]
) as 'Type'
but I'm not sure how to do that in BI. Basically, I'm looking at the value of a field in the JLE_LineTypeCategory table to match with the column name in the JobLedgerEntry table.
Since I only needed one set of field descriptors, I filtered the LineTypeCategory table to just the 3 possible values for the JobLedgerEntry.LineType field. I then merged the two tables on the optionInteger-LineType fields.

Updating jsonb field using concatenation operator in postgres

I am trying to update a jsonb field which has nested json objects in it using the concatenation operator in postgres as in dbfidde
But, it removes all other fields for example if I run the below script
UPDATE t
SET details = details || '{"name": {"firstname": "newname"},"address":{"city":"newCity"}}'
WHERE details -> 'name' ->>'firstname'='myname'
It removes the "lastname" field from the updated field
I tried updating with jsonb_set too but I am not sure how I can update multiple properties using jsonb_set
The || way does not work because the new name value is {"firstname":"newname"}. This replaces the complete old value {"firstname": "myname","lastname":"last"} and so removes the lastname attribute. This way only works if you are working on the toplevel fields. But you want to update the nested objects.
In that case I see no way around two separate calls of jsonb_set(). One possible way is to nest them:
demo:db<>fiddle
UPDATE t
SET details =
jsonb_set(
jsonb_set(details, '{name,firstname}','"newname"'),
'{address,city}',
'"newCity"'
)
WHERE details -> 'name' ->> 'firstname' = 'myname';
Updating the original details field; setting the new firstname value through the given path '{name,firstname}'
The resulting JSON object can be used directly for a following update of the city value using the same way.

How can I change post array value to allow insertion as Unique IDs (columns) mysql

$result = mysqli_query($link, "INSERT INTO mytable...
`friends`,
`friend1`,
`friend2`,
`friend3`,
VALUES (NULL, '$friends',
'$friends[0]'
'$friends[1]'
'$friends[2]'
Using cloneya.js to duplicate fields, I get an array value for a set of 3 names. Posting to mysql, I get three names in the in the first field(friends) but only the first,second and third letter of the first name in the subsequent fields (friend1-3). How can I insert each name to the separate fields?
$friends is not an array in your case, its just a string. Which means that $friends[0] will be the first character of that string, $friends[1] will be the second character and so on. You must send the friends with a different variable name so you have $friends which is a string and $otherName as an array which you can use in your sql query.
Keep in mind to use prepared statements when you use sql queries which depends on variables. Also convert your tables to 3NF.

web2py db query select showing field name

When i have the follow query:
str(db(db.items.id==int(row)).select(db.items.imageName)) + "\n"
The output includes the field name:
items.imageName
homegear\homegear.jpg
How do i remove it so that field name will not be included and just the selected imagename.
i tried referencing it like a list [1] gives me an out of range error and [0] i end up with:
<Row {'imageName': 'homegear\\homegear.jpg'}>
The above is not a list, what object is that and how can i reference on it?
Thanks!
John
db(db.items.id==int(row)).select(db.items.imageName) returns a Rows object, and its __str__ method converts it to CSV output, which is what you are seeing.
A Rows object contains Row objects, and a Row object contains field values. To access an individual field value, you must first index the Rows object to extract the Row, and then get the individual field value as an attribute of the Row. So, in this case, it would be:
db(db.items.id==int(row)).select(db.items.imageName)[0].imageName
or:
db(db.items.id==int(row)).select(db.items.imageName).first().imageName
The advantage of rows.first() over rows[0] is that the former returns None in case there are no rows, whereas the latter will generate an exception (this doesn't help in the above case, because the subsequent attempt to access the .imageName attribute would raise an exception in either case if there were no rows).
Note, even when the select returns just a single row with a single field, you still have to explicitly extract the row and the field value as above.

Dynamically Adding Columns to a DBIx::Class ResultSet

I have a DBIx::Class object representing an eBay auction. The underlying table has a description column which contains a lot of data. The description column is almost never used, so it's not included in the DBIx::Class column list for that table. That way, most queries don't fetch the auction description data.
I do, however, have one script that needs this column. In this one case, I want to access the contents of the description column as I would any other column:
$auction->description
How can I accomplish this without forcing all other queries to fetch the description column?
In older versions of DBIx::Class (not sure of the version number), the following used to work:
my $rs = $schema->resultset('Auctions');
my $lots = $rs->search(
undef,
{ '+select' => 'description', '+as' => 'description' },
);
That doesn't seem to work for row updates under modern versions of DBIx::Class. Trying that with an update
$auction->update({ description => '...'})
under DBIx::Class 0.08123 gives the following error: "DBIx::Class::Relationship::CascadeActions::update(): No such column description at ..."
Assuming that the script needing the extra column is running in its own process. You can do something like this:
my $rs = $schema->resultset('Auctions');
$rs->result_source->add_columns('description');
YourApp::Schema::Lots->add_columns('description');
YourApp::Schema::Lots->register_column('description');
Of course, that's a global change. After adding the column, other code in the same process will start fetching the description column in queries. Not to mention, it's kind of ugly.