473,761 Members | 4,421 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MySQL Extract BUG??

Assume a MYSQL table, foo.

One column, bar datetime.

Two rows:
2004-01-01 08:00:00
2004-02-01 08:00:00

select * from foo where extract(day from bar)=1;
2 rows in set...

select * from foo where extract(month from bar)=2;
1 row in set...

select * from foo where extract(month from bar)=1 && extract(day from
bar)=1;
1 row in set...

select * from foo where extract(month from bar)=2 && extract(day from
bar)=1;
Empty set... SHOULD BE 1 ROW!!!

MySQL version 4.0.13, running on Windows 2000.

Am I doing something incredibly stupid, or does this just make no sense?

Thanks,
Don
Jul 17 '05 #1
4 3271
On Mon, 05 Jan 2004 17:44:23 -0000, Don Crossman <dc*******@nosp am.email.com>
wrote:
Assume a MYSQL table, foo.

One column, bar datetime.

Two rows:
2004-01-01 08:00:00
2004-02-01 08:00:00

select * from foo where extract(day from bar)=1;
2 rows in set...

select * from foo where extract(month from bar)=2;
1 row in set...

select * from foo where extract(month from bar)=1 && extract(day from
bar)=1;
1 row in set...

select * from foo where extract(month from bar)=2 && extract(day from
bar)=1;
Empty set... SHOULD BE 1 ROW!!!

MySQL version 4.0.13, running on Windows 2000.

Am I doing something incredibly stupid, or does this just make no sense?


mysql> select * from foo;
+---------------------+
| bar |
+---------------------+
| 2004-01-01 08:00:00 |
| 2004-02-01 08:00:00 |
+---------------------+
2 rows in set (0.00 sec)

mysql> select * from foo where extract(day from bar)=1;
+---------------------+
| bar |
+---------------------+
| 2004-01-01 08:00:00 |
| 2004-02-01 08:00:00 |
+---------------------+
2 rows in set (0.00 sec)

mysql> select * from foo where extract(month from bar)=2;
+---------------------+
| bar |
+---------------------+
| 2004-02-01 08:00:00 |
+---------------------+
1 row in set (0.00 sec)

mysql> select * from foo where extract(month from bar)=1
-> and extract(day from bar)=1;
+---------------------+
| bar |
+---------------------+
| 2004-01-01 08:00:00 |
+---------------------+
1 row in set (0.00 sec)

mysql> select * from foo where extract(month from bar)=2
-> and extract(day from bar)=1;
+---------------------+
| bar |
+---------------------+
| 2004-02-01 08:00:00 |
+---------------------+
1 row in set (0.00 sec)

4.0.16, Linux.

--
Andy Hassall (an**@andyh.co. uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #2
Don Crossman wrote:
Two rows:
2004-01-01 08:00:00
2004-02-01 08:00:00 select * from foo where extract(month from bar)=2 && extract(day from
bar)=1;
Empty set... SHOULD BE 1 ROW!!! MySQL version 4.0.13, running on Windows 2000.


Works fine for me.

$ mysql --version
mysql Ver 12.22 Distrib 4.0.16, for pc-linux-gnu (i686)
Have you tried
: select extract(month from bar), extract(day from bar) from foo;
: select * from foo where (extract(month from bar)=2) && (extract(day from bar)=1);
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #3
Andy Hassall <an**@andyh.co. uk> wrote in
news:32******** *************** *********@4ax.c om:
On Mon, 05 Jan 2004 17:44:23 -0000, Don Crossman
<dc*******@nosp am.email.com> wrote:
Assume a MYSQL table, foo.

One column, bar datetime.

Two rows:
2004-01-01 08:00:00
2004-02-01 08:00:00

select * from foo where extract(day from bar)=1;
2 rows in set...

select * from foo where extract(month from bar)=2;
1 row in set...

select * from foo where extract(month from bar)=1 && extract(day from
bar)=1;
1 row in set...

select * from foo where extract(month from bar)=2 && extract(day from
bar)=1;
Empty set... SHOULD BE 1 ROW!!!

MySQL version 4.0.13, running on Windows 2000.

Am I doing something incredibly stupid, or does this just make no
sense?


mysql> select * from foo;
+---------------------+
| bar |
+---------------------+
| 2004-01-01 08:00:00 |
| 2004-02-01 08:00:00 |
+---------------------+
2 rows in set (0.00 sec)

mysql> select * from foo where extract(day from bar)=1;
+---------------------+
| bar |
+---------------------+
| 2004-01-01 08:00:00 |
| 2004-02-01 08:00:00 |
+---------------------+
2 rows in set (0.00 sec)

mysql> select * from foo where extract(month from bar)=2;
+---------------------+
| bar |
+---------------------+
| 2004-02-01 08:00:00 |
+---------------------+
1 row in set (0.00 sec)

mysql> select * from foo where extract(month from bar)=1
-> and extract(day from bar)=1;
+---------------------+
| bar |
+---------------------+
| 2004-01-01 08:00:00 |
+---------------------+
1 row in set (0.00 sec)

mysql> select * from foo where extract(month from bar)=2
-> and extract(day from bar)=1;
+---------------------+
| bar |
+---------------------+
| 2004-02-01 08:00:00 |
+---------------------+
1 row in set (0.00 sec)

4.0.16, Linux.


It looks like I'm off to the upgrade farm. Either that, or it's a Windows
bug!

Thank you, gentlemen.
Jul 17 '05 #4
Don Crossman <dc*******@nosp am.email.com> wrote in
news:Xn******** *************** **********@216. 168.3.44:
Andy Hassall <an**@andyh.co. uk> wrote in
news:32******** *************** *********@4ax.c om:
On Mon, 05 Jan 2004 17:44:23 -0000, Don Crossman
<dc*******@nosp am.email.com> wrote:
Assume a MYSQL table, foo.

One column, bar datetime.

Two rows:
2004-01-01 08:00:00
2004-02-01 08:00:00

select * from foo where extract(day from bar)=1;
2 rows in set...

select * from foo where extract(month from bar)=2;
1 row in set...

select * from foo where extract(month from bar)=1 && extract(day from
bar)=1;
1 row in set...

select * from foo where extract(month from bar)=2 && extract(day from
bar)=1;
Empty set... SHOULD BE 1 ROW!!!

MySQL version 4.0.13, running on Windows 2000.

Am I doing something incredibly stupid, or does this just make no
sense?


mysql> select * from foo;
+---------------------+
| bar |
+---------------------+
| 2004-01-01 08:00:00 |
| 2004-02-01 08:00:00 |
+---------------------+
2 rows in set (0.00 sec)

mysql> select * from foo where extract(day from bar)=1;
+---------------------+
| bar |
+---------------------+
| 2004-01-01 08:00:00 |
| 2004-02-01 08:00:00 |
+---------------------+
2 rows in set (0.00 sec)

mysql> select * from foo where extract(month from bar)=2;
+---------------------+
| bar |
+---------------------+
| 2004-02-01 08:00:00 |
+---------------------+
1 row in set (0.00 sec)

mysql> select * from foo where extract(month from bar)=1
-> and extract(day from bar)=1;
+---------------------+
| bar |
+---------------------+
| 2004-01-01 08:00:00 |
+---------------------+
1 row in set (0.00 sec)

mysql> select * from foo where extract(month from bar)=2
-> and extract(day from bar)=1;
+---------------------+
| bar |
+---------------------+
| 2004-02-01 08:00:00 |
+---------------------+
1 row in set (0.00 sec)

4.0.16, Linux.


It looks like I'm off to the upgrade farm. Either that, or it's a
Windows bug!

Thank you, gentlemen.


It apparently was a bug in the Windows version of 4.0.13. I just upgraded
to 4.0.17, and it all worked fine!
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3059
by: lkrubner | last post by:
I have a webserver through Rackspace. I create a domain. I create an FTP user. I upload some files. I create a database called testOfSetupScript and then I create a database user named setup. I write some PHP code which should, I think, be able to to auto create the tables. The SQL looks like this:
1
3238
by: forexgump | last post by:
I have a PHP script where I extract data from a file and insert it into a MySQL database. Every time I run the PHP script I receive an SQL error that states: "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near" ... and then it quotes a line from the file (where I'm trying to extract the data from) starting with an apostrophe. As an example, if the file...
0
1419
by: Federico Bari | last post by:
Hi all, I'm a bigginer using XML with Perl or PHP; I have to manage xml files storing datas of more than one table (inside the same xml file), and use it to update a mySQL database (the xml schema is a copy of the mySQL database). I'd like to know if somebody could suggest an easy and fast way to extract datas from each table and row or if you can suggest me simple tutorials. For example is it possible refer to a table inside the xml...
11
3825
by: kennthompson | last post by:
Trouble passing mysql table name in php. If I use an existing table name already defined everything works fine as the following script illustrates. <?php function fms_get_info() { $result = mysql_query("select * from $tableInfo") ; for ($i = 0; $i < mysql_num_rows($result); $i++) {
2
3197
by: Flic | last post by:
Hi, I have a basic db that I access with MySQL query browser. Everything seems fine to me but I am using this db as part of a php shopping basket and when I try to add an item I get: Notice: Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '>function.extract]: First argument should be an array in functions.inc.php on line 31
1
2063
by: bibie | last post by:
How to extract data from mssql and then convert it to mysql using VB6.0. How to connect the mssql..I know a little bit of VB6.0 but only create an interface using STANDARD EXE. Someone told me to create a script to extract data but i dont know how. Where should i create the script? ActiveX EXE or AvtiveX DLL. I really need help..Tq.
2
1697
by: clai83 | last post by:
mysql and mysqli functions always return strings values, and I understand that I can set the type of the data via the settype function AFTER I extract the data, but is there a way with PHP to extract the data as it is specified in the mysql database? (i.e if the type is an integer then PHP will insert the integer value in the result set). The reason I ask is I want to create a function to verify the integrity of the database before I process...
2
3981
by: trochia | last post by:
Hello all, I am fairly new to php etc, and I have a database 1) I have already did a search for: "Results within results" on this site, in PHP & MySQL forums ( I think) properly...and one search resulted in over 100 pages etc. From the below structure of my DB, I would like to get the code from the below URL working on my existing data I have, but I am having trouble and I am just getting flustered.... I would eventually like to...
0
9538
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9353
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10123
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9975
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9909
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8794
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5241
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3889
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3481
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.