Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strings not written to output file when using SQL CASE statement #181

Open
rmorgan10 opened this issue Apr 20, 2021 · 0 comments
Open

Strings not written to output file when using SQL CASE statement #181

rmorgan10 opened this issue Apr 20, 2021 · 0 comments

Comments

@rmorgan10
Copy link

When querying interactively, SQL CASE statements that yield string values work just fine. However, if you write the results of the query to a text file (either .csv or .tab), the column header is written but no values are written. If you write to a fits file, you get an error.

Here is an example of the observed behavior for csv file output:

easyaccess 1.4.7. The DESDM Database shell.
Connected as rmorgan to dessci.
** Type 'help' or '?' to list commands. **
            
_________
DESSCI ~> select RA, case when RA < 40 then 'A' when RA >= 40 then 'B' end as TEST from Y3_GOLD_2_2 where ROWNUM < 10;

    |☆             |  Ctrl-C to abort;  Rows : 9, Rows/sec: 39 

9 rows in 0.23 seconds

           RA TEST
1  317.659687    B
2  317.659688    B
3  317.659689    B
4  317.659689    B
5  317.659690    B
6  317.659690    B
7  317.659692    B
8  317.659692    B
9  317.659693    B

_________
DESSCI ~> select RA, case when RA < 40 then 'A' when RA >= 40 then 'B' end as TEST from Y3_GOLD_2_2 where ROWNUM < 10; > test_case.csv

Fetching data and saving it to test_case.csv ...


 Rows : 9, Rows/sec: 91  

 Written 9 rows to test_case.csv in 0.10 seconds and 1 trips


_________
DESSCI ~> ! cat test_case.csv
RA,TEST
35.48000000,
35.48000000,
35.48000000,
35.48000100,
35.48000100,
35.48000200,
35.48000200,
35.48000200,
35.48000200,
_________
DESSCI ~> 

If you instead use ints for the values in the CASE statement, then there are no problems with writing the output:

_________
DESSCI ~> select RA, case when RA < 40 then 0 when RA >= 40 then 1 end as TEST from Y3_GOLD_2_2 where ROWNUM < 10; > test_case.csv

Fetching data and saving it to test_case.csv ...


 Rows : 9, Rows/sec: 81 

 Written 9 rows to test_case.csv in 0.11 seconds and 1 trips


_________
DESSCI ~> ! cat test_case.csv
RA,TEST
35.48000000,0.00000000
35.48000000,0.00000000
35.48000000,0.00000000
35.48000100,0.00000000
35.48000100,0.00000000
35.48000200,0.00000000
35.48000200,0.00000000
35.48000200,0.00000000
35.48000200,0.00000000
_________
DESSCI ~> 

If you write the output to a fits file, ints work just fine, but string values in the CASE statement cause an error:

DESSCI ~> select RA, case when RA < 40 then 'A' when RA >= 40 then 'B' end as TEST from Y3_GOLD_2_2 where ROWNUM < 10; > test_case.fits

Fetching data and saving it to test_case.fits ...


 Rows : 9, Rows/sec: 147 
<class 'TypeError'>
data type "" not understood

_________
DESSCI ~> 
@rmorgan10 rmorgan10 changed the title Strings not written to CSV when using SQL CASE statement Strings not written to output file when using SQL CASE statement Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant