query to see class attribute - orientdb

Is there a SQL syntax to see the value of an class attribute using WebUI of OrientDB ?
I can use the following to edit the value : ALTER CLASS Employee CUSTOM minAge=16 (doc)
But I can't find a way to check out the value set.
I can do that using Java API : graph.getVertexType("Employee").getCustom("minAge")
I need this as a SQL query.
my orientdb version : 2.1.19

Try this:
SELECT FROM (
SELECT expand(classes) from metadata:schema
) WHERE name = 'theClassName'
OrientDB v 2.1.x is not supported anymore, I strongly suggest you to upgrade to v 3.0

Related

How to update an individual subfield for on a composite column on PostgreSQL using jOOQ?

On the PostgreSQL documentation there's an example about how to update a subfield of a composite type:
We can update an individual subfield of a composite column:
UPDATE mytab SET complex_col.r = (complex_col).r + 1 WHERE ...;
Assuming we are using jOOQ and code generation, how would that translate to jOOQ code?
As of jOOQ 3.15, there's no API to allow for accessing members of UDTs yet: https://github.com/jOOQ/jOOQ/issues/228
As always, you can easily work around this missing functionality by using plain SQL templating:
Field<Integer> r = field("({0}).{1}", COMPLEX_TYPE.R.getDataType(),
MYTAB.COMPLEX_COL.getUnqualifiedName(),
COMPLEX_TYPE.R.getUnqualifiedName()
);
ctx.update(MYTAB)
.set(r, r.plus(1))
.where(...)
.execute();

How to get attribute value from jsonb in postgresql using Panache and Hibernate?

I use quarkus-spring-data-jpa extension, but since native queries are not supported, I can't execute a query similar to this select * from test_table where test_json->>'FirstValue' = :value. I have not found how to do this using only JPQL. How can I make such a request using Hibernate and Panache ?

Postgres JSONB Check if JSON contains string using JPA

I have a jsonb column in my posgtgres table the json is of structure : {'alias':["name1","name2","name"....]}
I have written the Postgres query to check if the array in the JSON object contains the name.
select * from public.table t where json_col->'alias' ? 'name'
this works on pgAdmin
But same doesn't work in JPA
My code
#Query(value = "select * from public.table t where json_col->'alias' ? :name" ,nativeQuery = true)
Table findUsingName(#Param("name") String name);
This throws an error : 'Mixing of ? parameters and other forms like ?1 is not supported!'
I understand this error is due to the fact ? is also used by JPA is different sense...
Can anyone help me in the JPA Query
I don't know what the ? operator does, but you should use the named variant of the operator as a ? in JDBC is used to define a parameter.
Found the postgres function for '?' i.e. jsonb_exists_any(company_alias->'alias',ARRAY[:name])

PostgreSQL : IF UPDATING ( COLUMN NAME ) equivalent in postgres

I am doing a Oracle to EDB Migration. In oracle i have used :
IF UPDATING(column name) and :OLD.value <> :NEW.value THEN
But I am unable to use the syntax in Postgres and need to make changes. Kindly suggest how to implement the functionality in EDB.
If you use row trigger, then you can write
IF OLD.column_name IS DISTINCT FROM NEW.column_name THEN

OpenJpa how to find length of string in JPQL

I am using
length(ze.string)>2 in openJpa query. but i am getting
SQLCODE=-440, SQLSTATE=42884, SQLERRMC=CHAR_LENGTH;FUNCTION, DRIVER=3.53.95 {prepstmnt 1776269692 SELECT t0.f1, t0.f2, t0.f3, t0.f4, t0.f5, t0.f6, t0.f7, t0.f8, t0.f9, t0.f10, t0.f11, t0.f12, t0.f13, t0.f14, t0.f15, t0.f16, t0.f17 FROM table t0 WHERE (t0.f1 = ? AND CHAR_LENGTH(?) > ? AND .....
In plain query when i do length operation i am getting record but using jpa its not working. I looked Here used size it doesn't work. and the field is varchar and db2. trying from past 1 hour.
DB2 requires use of the SQL function LENGTH, yet OpenJPA seems to be incorrectly converting your JPQL to use SQL function CHAR_LENGTH (hence the error message - not that DB2 gives out clear messages saying what is wrong, who knows what SQLCODE=-440 is without having to search!!).
Raise a bug on your JPA provider.
See https://www.ibm.com/support/knowledgecenter/SSEPGG_9.7.0/com.ibm.db2.luw.sql.ref.doc/doc/r0000818.html
You would need to give more details about your entity, persistence.xml, and query to get to the bottom or this. However, I do not see how OpenJPA would use CHAR_LENGTH instead of LENGTH for DB2. Let me explain. If you look at DBDictionary here:
https://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?view=markup
You can see it defines something called "stringLengthFunction" as follows:
public String stringLengthFunction = "CHAR_LENGTH({0})";
This is the string length function which should be used for each individual dictionary (i.e. Database config). However, for DB2, the AbstractDB2Dictionary, see here:
https://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractDB2Dictionary.java?view=markup
overrides this as follows:
stringLengthFunction = "LENGTH({0})";
Given this, for DB2, LENGTH should be used. I took the following simple query:
"select me.id from MyEntity me where length(me.name)>2"
And executed it on OpenJPA using DB2, and I got this:
SELECT t0.ID FROM MYENTITY t0 WHERE (CAST(LENGTH(t0.ID) AS BIGINT) > CAST(? AS BIGINT)) [params=(long) 2]
Thanks,
Heath Thomann