Re: printing specific columns only

From: Gordon Burditt <gordonb.ncpnz_at_burditt.org>
Date: Tue, 08 Nov 2016 17:48:36 -0600
Message-ID: <0sKdnYDvFunJ-b_FnZ2dnUU7-f_NnZ2d_at_posted.internetamerica>


> Select * from archive where rain > '{0}

This looks like a syntax error. You have an unclosed single quote.

> but i want to print some other fields with it if rain is > 0

If you change the query to:

select * from archive where rain > 0;

it will print nothing if rain <= 0, so you don't have to worry about "leaving out" fields in that case.

Is rain a numeric quantity? If so, what does it mean to compare it against '{0}'? Numbers aren't supposed to have braces in them, and this doesn't look like the syntax for a prepared statement (which uses ? as a placeholder). Is something substituting values into the SQL before passing it to MySQL? What?

> So what i want is something like
>
> Select * from archive where rain > '{0}' print _at_datetime @rain

What fields do you expect that to print if rain > 0? What fields do you expect that to print if rain = 0?

What does:

        select datetime, rain from archive where rain > 0; do differently from what you want your above query to do?

> Is it possible or must i specify the fields in advance after select?

Do not fall in love with "select *". It may break things if columns are added or re-ordered. Or it may just be a waste of ink, if you only need some of the columns and are printing them on dead trees.

> Surely this is a simple thing that many people would do? I cant find a
> solution using google.

Surely I don't understand what you are trying to do.

> Thanks

It is possible to conditionally print blank columns in a select result with something like:

        select datetime, if(rain > 0, rain, ' ') from archive

which leaves the 'rain' column blank if it's zero. Received on Wed Nov 09 2016 - 00:48:36 CET

Original text of this message