I need to filter based on vertex attribute type SET or edge attribute type SET.
How to do it? Any hint will be appreciated.
When trying the following query, it returns an error:
- query:
select * from Person where id == 1 and email == "a1@gmail.com" limit 3
- err msg: The attribute type SET is not supported as a filter in WHERE clause
Please try as below
Person Vertex should have the attributes as id and email
SELECT p FROM Person:p WHERE p.id == 1 AND p.email == "a1@gmail.com" LIMIT 3
If the id is not selected as attribute use below
SELECT p FROM Person:p WHERE p == 1 AND p.email == "a1@gmail.com" LIMIT 3
Hi Sung Jeon,
Welcome to the TigerGraph community!
I assume that your Person
vertex is defined something like this:
CREATE VERTEX Person (PRIMARY_ID id INT, ..., email SET<STRING>, ...)
WITH PRIMARY_ID_AS_ATTRIBUTE="true"
I also assume that you used the SELECT
statement standalone, i.e. outside a query. Such SELECT
is one of the few built-in DML commands and this version of SELECT
has less functionality that the ones used within queries.
Within a query you can filter on SET
attributes:
CREATE QUERY filter_on_set(INT id, STRING email) FOR GRAPH MyGraph {
start = {Person.*};
res =
SELECT s
FROM start:s
WHERE s.id == id
AND s.email.contains(email);
PRINT res;
}
Notes:
- Within a query,
SET
datatype is converted to SetAccum
accumulator type and thus you can use SetAccum
's functions, like contains()
.
- You can learn more about the built-in DML commands by typing
HELP BASIC
in the gsql
command line tool.
- The
LIMIT
clause in your query has no effect if you filter by primary ID, as there could be only one instance of a vertex type with a given primary ID value; that’s why it’s a primary id