Data explorer doesn't show email address with a where clause

AI 生成的摘要

In a Discourse-hosted community, awlogan reported that the Data Explorer returns NULL for email addresses when using a WHERE clause filtering by created_at or id > 384, even though the query works with id > 0. riking explained that emails have been moved to a separate user_emails table, and the email column in the users table is no longer populated for new users — though it remains for legacy records. awlogan confirmed this explained the inconsistent behavior, and riking clarified that the column hasn’t been removed yet because not all code has been updated. awlogan acknowledged the explanation and planned to adjust queries to use the new user_emails table. This behavior is not a bug per se, but a consequence of schema evolution.

I’m trying to run a data explorer query to allow me to collect email addresses of the users signing up for our community. The primary goal here is to try to find out if they are a customer or partner of our company, assuming that they didn’t use a personal email address, then I can add them to the appropriate group.

The problem I’m having is that with a where clause in my query I get NULL returned on the email address in most cases. Here is the query I’m running:

SELECT u.username AS "username", u.email
FROM users u
WHERE u.created_at > '2017-09-11'

If I run this I get the NULL for email but otherwise it works. I read through the original data explorer thread and saw an example using user ID, which works if I set it to 0 in my where clause like this:

SELECT u.username AS "username", u.email
FROM users u
WHERE  u.id > 0

This works as expected. But if I change it to be above a certain value, in my case the last user to sign up before we opened the community up was 384, I get the same NULL values for email:

SELECT u.username AS "username", u.email
FROM users u
WHERE  u.id > 384

It feels like this is a bug as I wouldn’t expect the where clause to cause email addresses not to be shown, but it also seems to work inconsistently. I’m on a Discourse hosted account if that helps troubleshoot things.

Emails have been split out to their own table. Use the schema lookup on the right to find user_emails.

4 个赞

I did look through that, but why does it work sometimes and not others? Maybe it was changed after I started using it and those are legacy entries?

That’s exactly right. New users aren’t getting the column filled out, but it’s not deleted because not all the code has been updated yet.

3 个赞

OK thanks, that makes sense. I’ll work out the new table, thanks for the quick response.

2 个赞