question

ianphipps avatar image
ianphipps asked

How do I select all data from "p" attribute in SQL?

If I want all the data in a table, I can say something like "select * from [table_name]".

But in PlayFab, all the data I care about in my game is contained in the "p" attribute. I can't say "select p:*" because that gives an error. Instead, I have a giant query that has a line for every single bit of data, and if we add any, I have to figure out where to add it, which is pretty cumbersome.

Is there a way I can easily select all data from "p"?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
JayZuo avatar image
JayZuo answered

It seems you are using Snowflake. You need the "p" attribute because it's the payload in PlayStream events. This payload is a JSON object, if you want to get the elements inside this JSON object, you will need to use "p:". For more info, please see https://docs.snowflake.net/manuals/user-guide/querying-semistructured.html.

If you want to select all data from "p", you can just try "select p from [table_name]". This should be able to return the whole JSON to you.

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ianphipps avatar image ianphipps commented ·

"select p from [table_name]" gets me the raw JSON data all in one column, which is not useful to me. I need it to all be put into separate columns according to field name automatically. It seems like that just isn't possible.

0 Likes 0 ·
Andy avatar image Andy ♦♦ ianphipps commented ·

You are correct. The JSON payload in p does not adhere to a schema and, as such, you must provide the column names in your query. That's just the way Snowflake works. You could design views for specific event types that contained the column names for those events if you desired. This would let you build later queries more rapidly.

In our upcoming Data Warehouse feature (in private preview today) we do actually give you strongly-typed tables per event that can grow as you add events and fields. Please look for that being available in public preview in early 2019.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.