473,715 Members | 2,111 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 3266
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
3057
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
3236
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
1416
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
3815
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
3194
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
2062
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
1694
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
3977
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
8817
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
9193
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
9092
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
9037
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7963
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
5964
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4472
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...
2
2531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.