1

My SQL statement is as follows:

select col1,col2,"ABC" as col3 from ..

col3 is a constant string.

How to implement this SQL query via DolphinDB metaprogramming? I have tried sqlCol("ABC") or parseExpr, but they all treat "ABC" as a column name.

molddd123
  • 297
  • 6

2 Answers2

1

Because the argument passed to sqlCol is colName. The string "ABC" needs to be included in a metacode, which can be achieved by sqlColAlias and parseExpr with the following script:

sqlColAlias(<"ABC">,"col3")
parseExpr(" `ABC as col3")

The output is:

< "ABC" as col3 >
zhihengqu
  • 371
  • 5
-1
sqlColAlias([<col1>, <col2>, <"ABC">], `col1`col2`col3)
Hanwei Tang
  • 413
  • 3
  • 10
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/34284417) – AwkwardCoder Apr 26 '23 at 09:57
  • @AwkwardCoder Please pay attention when reviewing. This is not a link-only answer. And although code-only answers are generally frowned upon, they are answers. Downvoting would be the appropriate action, not voting to delete. – Mark Rotteveel Apr 26 '23 at 16:02