Can we access the primary id if not set as attribute

Hello TG Team,
Is there a way to access the primary id of a vertex if pid not set as attribute in the schema? 99% of my use cases don’t need to access primary id directly, but sometimes I just need to filter the target vertices using PIDs.

Hi @luyilun32661,

Unfortunately, you will not be able to filter or search by primary id (using an expression) unless you have set the primary id as an attribute. Errors will be encountered when trying to access the value because it has not been stored in the database.

When you set the primary id as an attribute, under the hood it is actually replicating the field (an id field plus a searchable attribute field). The purpose of the primary id not being an attribute by default is to minimize storage for vertices. The consequence is that your query will not be able to read/use the primary id in an expression.

I typically like to check the ‘as attribute’ box when creating my graph schemas for convenience sake unless I know the id really isn’t meaningful in any use case/query.

I hope this helps!


I would recommend going through McKenzie’s suggestion. However, alternatively, if you do not want to use the primary id as an attribute, you can filter through it using external TigerGraph tools like pyTigerGraph or simply running the query via its REST endpoint. When returning the vertex set results, it will include the vertex ids, so you could write a script to filter through it.