-
Hi everyone, I have added some details to the In a previous discussion, I was unable to use the Now, I have a similar problem: It seems that some PostgreSQL functions and operators are not supported. I tried using The question is: Here's how the info is stored in the DB, the {
"Id": 10,
"UserId": "****",
"UserName": "****",
"NormalizedUserName": "****",
"Email": "****",
"NormalizedEmail": "****",
"PasswordHash": "****",
"SecurityStamp": "****",
"EmailConfirmed": true,
"PhoneNumberConfirmed": false,
"IsEnabled": true,
"TwoFactorEnabled": false,
"IsLockoutEnabled": true,
"AccessFailedCount": 0,
"RoleNames": [
"Administrator"
],
"UserClaims": [],
"LoginInfos": [],
"UserTokens": [],
"Properties": {
"UserNotificationPreferencesPart": {
"Methods": [
"Email"
],
"Optout": []
},
"UserDetails": {
"ContentItemId": "****",
"ContentItemVersionId": null,
"ContentType": "UserDetails",
"DisplayText": "",
"Latest": false,
"Published": false,
"ModifiedUtc": "2024-04-16T08:26:11.7923065Z",
"PublishedUtc": null,
"CreatedUtc": null,
"Owner": "",
"Author": "TestUserAdmin",
"UserDetails": {
"Name": {
"Text": "Pippo"
},
"Surname": {
"Text": "Pluto"
},
"Phone": {
"Text": "+39123456789"
},
"WhatsApp": {
"Text": null
},
"Street": {
"Text": "Via del Colosseo"
},
"StreetNumber": {
"Text": "1"
},
"City": {
"Text": "Rome"
}
}
}
}
} This is the first query I tried and it doesn't work: SELECT
UI.DocumentId,
UI.UserId,
UI.NormalizedUserName,
UI.NormalizedEmail,
STRING_AGG(UBRNI.RoleName, ',') AS RoleNames,
STRING_AGG(casttotext(UBRNID.UserByRoleNameIndexId), ',') AS RoleIds,
json_extract_path_text(D.Content, 'Properties', 'UserDetails', 'Name') AS FirstName,
json_extract_path_text(D.Content, 'Properties', 'UserDetails', 'Surname') AS LastName,
json_extract_path_text(D.Content, 'Properties', 'UserDetails', 'Phone') AS Phone,
json_extract_path_text(D.Content, 'Properties', 'UserDetails', 'Street') AS Street,
json_extract_path_text(D.Content, 'Properties', 'UserDetails', 'StreetNumber') AS StreetNumber,
json_extract_path_text(D.Content, 'Properties', 'UserDetails', 'City') AS City
FROM
UserIndex UI
JOIN
Document D ON UI.DocumentId = D.Id
JOIN
UserByRoleNameIndex_Document UBRNID ON UI.DocumentId = UBRNID.DocumentId
JOIN
UserByRoleNameIndex UBRNI ON UBRNID.UserByRoleNameIndexId = UBRNI.Id
GROUP BY
UI.DocumentId,
UI.UserId,
UI.NormalizedUserName,
UI.NormalizedEmail,
D.Content The second query that doesn't work: SELECT
UI.DocumentId,
UI.UserId,
UI.NormalizedUserName,
UI.NormalizedEmail,
STRING_AGG(UBRNI.RoleName, ',') AS RoleNames,
STRING_AGG(casttotext(UBRNID.UserByRoleNameIndexId), ',') AS RoleIds,
D.Content #>> '{Properties, UserDetails, Name}' AS FirstName,
D.Content #>> '{Properties, UserDetails, Surname}' AS LastName,
D.Content #>> '{Properties, UserDetails, Phone}' AS Phone,
D.Content #>> '{Properties, UserDetails, Street}' AS Street,
D.Content #>> '{Properties, UserDetails, StreetNumber}' AS StreetNumber,
D.Content #>> '{Properties, UserDetails, City}' AS City
FROM
UserIndex UI
JOIN
Document D ON UI.DocumentId = D.Id
JOIN
UserByRoleNameIndex_Document UBRNID ON UI.DocumentId = UBRNID.DocumentId
JOIN
UserByRoleNameIndex UBRNI ON UBRNID.UserByRoleNameIndexId = UBRNI.Id
GROUP BY
UI.DocumentId,
UI.UserId,
UI.NormalizedUserName,
UI.NormalizedEmail,
D.Content The third query that works, but returns a JSON string, and is not what I want: SELECT
UI.DocumentId,
UI.UserId,
UI.NormalizedUserName,
UI.NormalizedEmail,
STRING_AGG(UBRNI.RoleName, ',') AS RoleNames,
STRING_AGG(casttotext(UBRNID.UserByRoleNameIndexId), ',') AS RoleIds,
D.Content AS UserDetailsJSON
FROM
UserIndex UI
JOIN
Document D ON UI.DocumentId = D.Id
JOIN
UserByRoleNameIndex_Document UBRNID ON UI.DocumentId = UBRNID.DocumentId
JOIN
UserByRoleNameIndex UBRNI ON UBRNID.UserByRoleNameIndexId = UBRNI.Id
GROUP BY
UI.DocumentId,
UI.UserId,
UI.NormalizedUserName,
UI.NormalizedEmail,
D.Content Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
@lampersky maybe you have a quick solution as in the previous discussion 😊🙃🤔 @sebastienros as for the previous discussion, could be useful to add this as a feature in the generic dialect? Thank you |
Beta Was this translation helpful? Give feedback.
-
@MarGraz this is an error from postgreSQL not from parser, which means the query is grammatically correct, I don't have postgreSQL instance to test, please first try your query with pgAdmin, other than that make sure your postgreSQL version supports this json function |
Beta Was this translation helpful? Give feedback.
@lampersky in the end, the problem was related to some syntax errors and the cast
::
, as explained in the previous messages.Now this query works because I have implemented a custom function to cast from
text
tojsonb
: