[GRASSLIST:8334] RE: db.execute syntax

Hmm...I gave that a try, with the following results:

echo 'UPDATE Opil184a_ship_nav_med_smth SET MOD_60 = 1 WHERE CAT % 60 = 0'
| db.execute

dbmi: Protocol error (invalid table/column name or unsupported column type)
ERROR: Error while executing: "UPDATE Opil184a_ship_nav_med_smth SET MOD_60
       = 1 WHERE CAT % 60 = 0

db.describe shows that my cat and MOD_60 columns are indeed INT. So I'm not
sure why there's a problem with the table column name/type.

Perhaps quotation marks are needed somewhere?

~ Eric.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

-----Original Message-----
From: Glynn Clements [mailto:glynn@gclements.plus.com]
Sent: Monday, September 19, 2005 12:40 PM
To: Patton, Eric
Cc: GRASSLIST@baylor.edu
Subject: Re: [GRASSLIST:8332] db.execute syntax

Patton, Eric wrote:

I'm having a bit of trouble getting my syntax right for this SQL

statement.

I want the query to read through all the cat values in the table, and
enter the value "1" in an empty column wherever the cat value is
divisible by 60 with no remainder (cat % 60 == 0). Here's what I enetered:

echo 'UPDATE Opil184a_ship_nav_med_smth SET MOD_60==1 WHERE
(cat%60)==0' | db.execute

                                                     ^^ You're using '=='
for an assignment, when it should be '='.

--
Glynn Clements <glynn@gclements.plus.com>

On Mon, 19 Sep 2005 13:01:41 -0300
"Patton, Eric" <epatton@nrcan.gc.ca> wrote:

Hmm...I gave that a try, with the following results:

echo 'UPDATE Opil184a_ship_nav_med_smth SET MOD_60 = 1 WHERE CAT % 60 = 0'
| db.execute

dbmi: Protocol error (invalid table/column name or unsupported column type)
ERROR: Error while executing: "UPDATE Opil184a_ship_nav_med_smth SET MOD_60
       = 1 WHERE CAT % 60 = 0

db.describe shows that my cat and MOD_60 columns are indeed INT. So I'm not
sure why there's a problem with the table column name/type.

Perhaps quotation marks are needed somewhere?

~ Eric.

This is rather inane, but you do have the case correct? is is CAT not cat and MOD_60 not mod_60??

T
--
Trevor Wiens
twiens@interbaun.com

The greatest obstacle to discovery is not ignorance - it is the illusion of knowledge.
(Daniel J. Boorstin)

Patton, Eric wrote:

echo 'UPDATE Opil184a_ship_nav_med_smth SET MOD_60 = 1 WHERE CAT % 60 = 0' | db.execute

                                                                        ^

Here you've made the opposite mistake, using '=' for an equality check
when it should be '=='.

What does the following do:

echo 'UPDATE Opil184a_ship_nav_med_smth SET MOD_60 = 1 WHERE CAT % 60 == 0' | db.execute

?

--
Glynn Clements <glynn@gclements.plus.com>

On Mon, 19 Sep 2005 17:19:00 +0100
Glynn Clements <glynn@gclements.plus.com> wrote:

Patton, Eric wrote:

> echo 'UPDATE Opil184a_ship_nav_med_smth SET MOD_60 = 1 WHERE CAT % 60 = 0' | db.execute
                                                                        ^

Here you've made the opposite mistake, using '=' for an equality check
when it should be '=='.

Glynn,

Correct me if I'm wrong but to my knowledge == and = are not used in SQL the way they are in C for example. In fact AFAIK == is not used at all in standard SQL, it isn't referenced in the PostgreSQL documentation for 8.0 that I can find.

T
--
Trevor Wiens
twiens@interbaun.com

The greatest obstacle to discovery is not ignorance - it is the illusion of knowledge.
(Daniel J. Boorstin)

Trevor Wiens wrote:

> Patton, Eric wrote:
>
> > echo 'UPDATE Opil184a_ship_nav_med_smth SET MOD_60 = 1 WHERE CAT % 60 = 0' | db.execute
> ^
>
> Here you've made the opposite mistake, using '=' for an equality check
> when it should be '=='.

Correct me if I'm wrong but to my knowledge == and = are not used in
SQL the way they are in C for example. In fact AFAIK == is not used at
all in standard SQL, it isn't referenced in the PostgreSQL
documentation for 8.0 that I can find.

You're right; I got confused by the presence of "==" in the original
version. Both should be "=", which was Eric's second attempt.

--
Glynn Clements <glynn@gclements.plus.com>

Patton, Eric wrote:

Hmm...I gave that a try, with the following results:

echo 'UPDATE Opil184a_ship_nav_med_smth SET MOD_60 = 1 WHERE CAT % 60 = 0'
| db.execute

dbmi: Protocol error (invalid table/column name or unsupported column type)
ERROR: Error while executing: "UPDATE Opil184a_ship_nav_med_smth SET MOD_60
       = 1 WHERE CAT % 60 = 0

db.describe shows that my cat and MOD_60 columns are indeed INT. So I'm not
sure why there's a problem with the table column name/type.

Which database backend is this using? The DBF driver doesn't support
the modulus (%) operator. Even so, the error message seems inaccurate.

PostgreSQL doesn't have any problems with the above command.

--
Glynn Clements <glynn@gclements.plus.com>