planetarydev / json-sql-builder2

Level Up Your SQL-Queries
MIT License
75 stars 21 forks source link

Support for Virtual Column in Select Statement for Postgres #17

Closed umer-mehmood closed 5 years ago

umer-mehmood commented 5 years ago

We need to add a virtual column in select statement while composing the sql query.

Use Case: We are trying to build a query using postgresql dialect. The query then will be executed on AWS Athena Service. And in case of virtual columns athena requires string values in single qoutes i.e. 'value' as "Column_Name". So the issue is json-sql-builder2 does not add single qoutes for the value of virtual column. Let me know if there is any way. Thanks

planetarydev commented 5 years ago

Did you mean something like this?

SELECT 'myvalue' AS "my_column" FROM "my_table"

You can use the InlineSQL-helper __ like:

result = sql.build({
  $select: {
    my_column: { __: "'myvalue'" }
    $from: 'my_table'
  }
});

Please have a look at https://github.com/planetarydev/json-sql-builder2/tree/master/sql/helpers/misc/__

umer-mehmood commented 5 years ago

Did you mean something like this?

SELECT 'myvalue' AS "my_column" FROM "my_table"

You can use the InlineSQL-helper __ like:

result = sql.build({
  $select: {
    my_column: { __: "'myvalue'" }
    $from: 'my_table'
  }
});

Please have a look at https://github.com/planetarydev/json-sql-builder2/tree/master/sql/helpers/misc/__

This fulfills my requirement. Thank you!!!