astropy / astropy/astroquery

Query with Select on Calculated Column

Open
#1,549 4 comments 0 reactions 0 assignees View on GitHub
gama question
Dominant language
Python
Stars
791
Forks
451
Avg merge
1d 3h
Merged PRs (30d)
4

Description

I tried unsuccesfully to run this query

Straight line of Graph Absolute M_r versus u-r rest frame
y = mx + c where m = -0.083 and c = 0.58

```
import numpy as np
import scipy.stats as st
from astroquery.gama import GAMA
import matplotlib.pyplot as plt
Straight line of Graph Absolute M_r versus u-r rest frame
y = mx + c where m = -0.083 and c = 0.58
x_col = ' absmag_r, '
y_col = ' uminusr, '
y_del = ' (0.58 - absmag_r * 0.083) - uminusr as y_del '
query = 'SELECT '+x_col+y_col+y_del+' FROM StellarMasses \
WHERE y_del < 0.3 LIMIT 10'
print(query)
result = GAMA.query_sql(query)
print(result)
```

But it gives me an error.

I assume it does not like the calculated column y_del.

I note if I leave off the WHERE it produces the table ok.

I am struggling to think of a way forward if both selection on calculated columns and creation of tables from queries is not supported.

What do other people do?

Contributor guide

Open the contributing guide

Research direction

The issue names GAMA.query_sql and the StellarMasses query; start by reproducing the query with and without the WHERE clause and capture the exact error. Done means the supported behavior for filtering on the calculated y_del column is established, with the result documented or a clear workaround identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.