function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
THustonTHuston 

SOQL From Syntax BNF question

I'm writing a parser that will extract Fields and Sobjects from a SOQL query.

 

I have a question about the syntax.

 

The BNF lists:

'FROM' UNQUALIFIEDNAME ('AS' ? UNQUALIFIEDNAME)? ('USING' UNQUALIFIEDNAME)? (PARENT_ALIAS_EXPR)*

What does the optional USING do, and look like in a query?

I can't find it in any SQL or SOQL docs and I need to be able to resolve any alias names back to the true SObject so I can get the Field's Type.

 

 

werewolfwerewolf

Not sure where you got that BNF; the API docs on SELECT has the following pseudo-BNF:

 

SELECT fieldListFROM objectType[WHERE conditionExpression]
[WITH [DATA CATEGORY] filteringExpression]
[GROUP BY fieldGroupByList] | [GROUP BY ROLLUP|CUBE (fieldSubtotalGroupByList)]
[HAVING havingConditionExpression]
[ORDER BYfieldOrderByList ASC | DESC ? NULLS FIRST | LAST ?]
[LIMIT ?]

 

THustonTHuston

Sorry, should have put up the link to the BNF over in Integration - API

 

The API doc is equally confusing as it does not show a full description of the syntax.

 

I think the BNF was from an earlier API version or was modified from some other SQL's BNF.

This valid SOQL query cannot be generated from the posted BNF:

SELECT Id, Name FROM Account WHERE Id IN (SELECT AccountId FROM Opportunity )

 

I also think the API doc was made by someone who didn't care.

objectType Specifies the type of object that you want to query(). You must specify a valid object and must have read-level permissions to that object.

wtf is that?  It is certainly not a description of valid syntax.

I've found this to be valid for the 'objectType' clause:

SELECT act.name, act.id, status, ccon.lastname FROM case as cs, case.account act, cs.contact ccon

I've never found the 'AS' modifier used anywhere in the API doc.  But it is valid, so I have to account for it.

 

I'm being forced to parse SOQL text and I can't find a description or examples of all the possible variations.

 

 

THustonTHuston
I only need the variations of the SELECT and FROM to gather my QueryResult Metadata (a Field's name and its DataType).  It seems like this should be documented somewhere, but I cannot find it.
THustonTHuston
So anyway.  Has anyone used the USING clause?