Bluehost.com Web Hosting $6.95

SELECT errors out saying a column doesn't exist that SHOW COLUMNS thinks does exist

This is a discussion on SELECT errors out saying a column doesn't exist that SHOW COLUMNS thinks does exist within the MySQL Database forums, part of the Database Forums category; When I do "SELECT port, behavior FROM ip_addresses", I get an error 1054: Unknown column 'port' in 'field ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-09-2007
yawnmoth
 
Posts: n/a
Default SELECT errors out saying a column doesn't exist that SHOW COLUMNS thinks does exist

When I do "SELECT port, behavior FROM ip_addresses", I get an error
1054: Unknown column 'port' in 'field list'.

Doing a "SHOW COLUMNS FROM ip_addresses", however, shows that I *do*
in fact have a column 'port'. Here's the exact output I get:

Array
(
[Field] => ip_address
[Type] => varchar(8)
[Null] =>
[Key] => PRI
[Default] =>
[Extra] =>
)

Array
(
[Field] => behavior
[Type] => tinyint(2)
[Null] =>
[Key] =>
[Default] => 0
[Extra] =>
)

Array
(
[Field] => port
[Type] => varchar(4)
[Null] => YES
[Key] =>
[Default] => 0
[Extra] =>
)

Array
(
[Field] => last_checked
[Type] => int(11)
[Null] =>
[Key] =>
[Default] => 0
[Extra] =>
)

So why is MySQL simultaneously telling me that 'port' is a column and
isn't? And what can I do to fix it?

If it matters, the MySQL server in question is running on
ipowerweb.com.

Reply With Quote
  #2 (permalink)  
Old 02-09-2007
Lee Peedin
 
Posts: n/a
Default Re: SELECT errors out saying a column doesn't exist that SHOW COLUMNS thinks does exist

On 9 Feb 2007 09:52:52 -0800, "yawnmoth" <terra1024@yahoo.com> wrote:

>When I do "SELECT port, behavior FROM ip_addresses", I get an error
>1054: Unknown column 'port' in 'field list'.
>


Try

"SELECT `port`, behavior FROM ip_addresses"

and see if that works - if so, MySQL is treating "port" as a "reserved
word".

Lee

Reply With Quote
  #3 (permalink)  
Old 02-09-2007
yawnmoth
 
Posts: n/a
Default Re: SELECT errors out saying a column doesn't exist that SHOW COLUMNS thinks does exist

On Feb 9, 2:09 pm, Lee Peedin <lpeedinDONOTSP...@nc.rr.com> wrote:
> On 9 Feb 2007 09:52:52 -0800, "yawnmoth" <terra1...@yahoo.com> wrote:
>
> >When I do "SELECT port, behavior FROM ip_addresses", I get an error
> >1054: Unknown column 'port' in 'field list'.

>
> Try
>
> "SELECT `port`, behavior FROM ip_addresses"
>
> and see if that works - if so, MySQL is treating "port" as a "reserved
> word".
>
> Lee


Just tried it. Still get the same error :(

Reply With Quote
  #4 (permalink)  
Old 02-09-2007
Rik
 
Posts: n/a
Default Re: SELECT errors out saying a column doesn't exist that SHOW COLUMNS thinks does exist

On Fri, 09 Feb 2007 21:44:37 +0100, yawnmoth <terra1024@yahoo.com> wrote:

> On Feb 9, 2:09 pm, Lee Peedin <lpeedinDONOTSP...@nc.rr.com> wrote:
>> On 9 Feb 2007 09:52:52 -0800, "yawnmoth" <terra1...@yahoo.com> wrote:
>>
>> >When I do "SELECT port, behavior FROM ip_addresses", I get an error
>> >1054: Unknown column 'port' in 'field list'.

>>
>> Try
>>
>> "SELECT `port`, behavior FROM ip_addresses"
>>
>> and see if that works - if so, MySQL is treating "port" as a "reserved
>> word".
>>
>> Lee

>
> Just tried it. Still get the same error :(
>


What does a SHOW CREATE TABLE `ip_adresses` show?

--
Rik Wasmus
Reply With Quote
  #5 (permalink)  
Old 02-10-2007
yawnmoth
 
Posts: n/a
Default Re: SELECT errors out saying a column doesn't exist that SHOW COLUMNS thinks does exist

On Feb 9, 3:04 pm, Rik <luiheidsgoe...@hotmail.com> wrote:
> <snip>
> What does a SHOW CREATE TABLE `ip_adresses` show?


[Table] => phpbb_proxies
[Create Table] => CREATE TABLE `ip_addresses` (
`ip_address` varchar(8) NOT NULL default '',
`behavior` tinyint(2) NOT NULL default '0',
`port ` varchar(4) default '0',
`last_checked` int(11) NOT NULL default '0',
PRIMARY KEY (`ip_address`)
) TYPE=MyISAM

Reply With Quote
  #6 (permalink)  
Old 02-10-2007
Rik
 
Posts: n/a
Default Re: SELECT errors out saying a column doesn't exist that SHOW COLUMNS thinks does exist

On Sat, 10 Feb 2007 02:18:52 +0100, yawnmoth <terra1024@yahoo.com> wrote:

> On Feb 9, 3:04 pm, Rik <luiheidsgoe...@hotmail.com> wrote:
>> <snip>
>> What does a SHOW CREATE TABLE `ip_adresses` show?

>
> [Table] => phpbb_proxies
> [Create Table] => CREATE TABLE `ip_addresses` (
> `ip_address` varchar(8) NOT NULL default '',
> `behavior` tinyint(2) NOT NULL default '0',
> `port ` varchar(4) default '0',


Did you spot the space (or maybe it's another whitespace character)?

SELECT `port ` FROM `phpbb_proxies`

Another fine reason to always use backticks :)
--
Rik Wasmus
Reply With Quote
  #7 (permalink)  
Old 02-10-2007
Rik
 
Posts: n/a
Default Re: SELECT errors out saying a column doesn't exist that SHOW COLUMNS thinks does exist

On Sat, 10 Feb 2007 02:41:12 +0100, Rik <luiheidsgoeroe@hotmail.com> wrote:

> On Sat, 10 Feb 2007 02:18:52 +0100, yawnmoth <terra1024@yahoo.com> wrote:
>
>> On Feb 9, 3:04 pm, Rik <luiheidsgoe...@hotmail.com> wrote:
>>> <snip>
>>> What does a SHOW CREATE TABLE `ip_adresses` show?

>>
>> [Table] => phpbb_proxies
>> [Create Table] => CREATE TABLE `ip_addresses` (
>> `ip_address` varchar(8) NOT NULL default '',
>> `behavior` tinyint(2) NOT NULL default '0',
>> `port ` varchar(4) default '0',

>
> Did you spot the space (or maybe it's another whitespace character)?
>
> SELECT `port ` FROM `phpbb_proxies`
>
> Another fine reason to always use backticks :)


Hmmz, I'm actually curious how this came to be. My MySQL 5.0 won't let me
create it.

If you're still having troubles selecting from it with a space I suspect
it's some weird character. Easiest way to solve it:

CREATE TABLE `ip_addresses_temp` (
`ip_address` varchar(8) NOT NULL default '',
`behavior` tinyint(2) NOT NULL default '0',
`port` varchar(4) default '0',
`last_checked` int(11) NOT NULL default '0',
PRIMARY KEY (`ip_address`)
) TYPE=MyISAM

INSERT INTO `ip_addresses_temp` SELECT * FROM `ip_addresses`

DROP TABLE `ip_addresses`

RENAME TABLE ip_addresses_temp TO ip_addresses

--
Rik Wasmus
Reply With Quote
  #8 (permalink)  
Old 02-10-2007
yawnmoth
 
Posts: n/a
Default Re: SELECT errors out saying a column doesn't exist that SHOW COLUMNS thinks does exist

On Feb 9, 7:55 pm, Rik <luiheidsgoe...@hotmail.com> wrote:
> On Sat, 10 Feb 2007 02:41:12 +0100, Rik <luiheidsgoe...@hotmail.com> wrote:
> > On Sat, 10 Feb 2007 02:18:52 +0100,yawnmoth<terra1...@yahoo.com> wrote:

>
> >> On Feb 9, 3:04 pm, Rik <luiheidsgoe...@hotmail.com> wrote:
> >>> <snip>
> >>> What does a SHOW CREATE TABLE `ip_adresses` show?

>
> >> [Table] => phpbb_proxies
> >> [Create Table] => CREATE TABLE `ip_addresses` (
> >> `ip_address` varchar(8) NOT NULL default '',
> >> `behavior` tinyint(2) NOT NULL default '0',
> >> `port ` varchar(4) default '0',

>
> > Did you spot the space (or maybe it's another whitespace character)?


Nope. Nice catch! :D

>
> > SELECT `port ` FROM `phpbb_proxies`

>
> > Another fine reason to always use backticks :)

>
> Hmmz, I'm actually curious how this came to be. My MySQL 5.0 won't let me
> create it.


I was using MySQL 4.0.18.

Anyway, thanks! :)

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 04:33 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0