Skip to content

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

@rmorgan10

Description

@rmorgan10

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 ~> 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions