This is because PostgreSQL can handle inserting 123, 12.3 and '123' into an int column but not '12.3' which is what is happening in the PDO driver. PHP converts numbers about PHP_INT_MAX to floats and the PDO driver seems to be quoting this value as it inserts it.
Ideally we need to find a way to remove these quotes or auto cast within postgres.
Comment | File | Size | Author |
---|---|---|---|
#40 | 515310-bigint-doh-and-64-bit-check.patch | 1.64 KB | gustavb |
#36 | 515310-bigint-doh.patch | 1.07 KB | Josh Waihi |
#34 | 515310-bigint-doh.patch | 1.08 KB | Josh Waihi |
#11 | 515310-11-PHP_INT_MAX.patch | 2.08 KB | marcvangend |
#9 | 515310-PHP_INT_MAX.patch | 2.08 KB | Josh Waihi |
Comments
Comment #1
markir CreditAttribution: markir commentedIt looks to me like this is sorted in Php 6.0. I trawled around in the code to find what had been changed, and have what I Think is the relevant diff attached to:
http://bugs.php.net/bug.php?id=48924
This seems to fix the issue cleanly. Its worth noting that Mysql users will experience the same sort of error as Postgres if STRICT_ALL_TABLES or similar is switched on (Actually they won't.... I was looking at the 64-bit case by mistake).
Comment #2
markir CreditAttribution: markir commentedThe PDO developers have fixed this issue and committed a patch to 5.2, 5.3 and 6.0 branches. For this interested, this bug was introduced in a fix for another similar issue (loss of decimal data in prepared statements http://bugs.php.net/bug.php?id=41698). I could not exhibit our bug on Php6 because it was not patched for 41698! Presumably the fix for our bug will be in the next point release of php.
Comment #3
Josh Waihi CreditAttribution: Josh Waihi commentedWill keep an eye out to see when this fix come through the ubuntu and debian repositories - hopefully before D7 release.
Comment #4
chx CreditAttribution: chx commentedWe really should find some way to code around this bug. It's not enough that some future PHP will work for D7...
Comment #5
Josh Waihi CreditAttribution: Josh Waihi commentedBecause Drupal 7 requires PHP 5.2 and the fix is in 5.2 - I don't agree that a work around is required, however, I agree with chx, as he mentioned in IRC, because this is a fatal bug for Drupal+PostgreSQL, Drupal shouldn't allow users to install Drupal if the bug exists in there version of PHP/PDO instead, ask them to upgrade to the latest version of Drupal as an outdated version of PHP 5.2 is just as bad as having an outdated version of Drupal running.
My solution will be to run a task at install time to ensure the bug does not exist. If it does then indicate this when the user enters there database credentials. Postponing this issue until #349508: Require UTF8 database encoding get into core so we can create a task to run this test.
Comment #6
marcvangend#349508 is closed, is there anything left to do here?
Comment #7
Josh Waihi CreditAttribution: Josh Waihi commentedwell, technically, we should add a check for the postgres install driver to see if PHP is at the right version. We need to find out which version of PHP 5.2 it is fixed in (same for PHP 5.3).
Comment #8
marcvangendLooks like it was fixed here: http://bugs.php.net/bug.php?id=48924. I can't find that bugfix in the php changelog at http://www.php.net/ChangeLog-5.php, but the commit message is at http://svn.php.net/viewvc?view=revision&revision=284208. Looking at the date (July 16 2009), the fix must have been included in PHP 5.2.11 and 5.3.1.
Comment #9
Josh Waihi CreditAttribution: Josh Waihi commentedOK, attached is a patch that test PHP to see if PostgreSQL can run on it. I've tested the installer and it works. I've made it so that it only warns the user about the issue rather than prevents the user from installing Drupal. The warning shows during the entire install process so it makes its mark clear. I'd be happy for it to be commited but I just need someone to look over the comments and the language used.
Comment #10
marcvangendJosh, there is a small mistake in the patch, in the warning message it says "5.3.11" where it should say "5.2.11".
Comment #11
marcvangendHere is a new patch, fixing the mistake from #10 and another minor typo. Note that I didn't actually test the patch (I don't have PGSQL running here) so I don't feel qualified to say this is RTBC.
Comment #12
Dries CreditAttribution: Dries commentedAny reason this is not using the _requirements() hook?
Comment #13
Josh Waihi CreditAttribution: Josh Waihi commented#342950: Compatibility stored procedures should be defined in includes/database/pgsql saw the Database driver actually use the install PHP class they have. We defined that these would be used to check and initialize the database environments for Drupal rather than have case conditions in the system module. If you prefer, we could move the driver checks to system_requirements but thats another issue.
Comment #14
catchLet's move driver checks to another issue. Also even the code comments in the patch state this isn't critical.
Comment #15
Dries CreditAttribution: Dries commentedCould we add a
@Todo: remove in D8
comment?
Comment #16
Crell CreditAttribution: Crell commentedThis is a driver-specific requirement so adding it in the install class for that driver is correct. hook_requirements() is for Drupal-specific requirements. Database drivers are specifically designed to allow for driver-specific requirements for exactly this reason. :-)
If we include a todo, it should say to remove when we start requiring 5.2.12 / 5.3.1. We don't know yet if Drupal 8 will do so. A todo to that effect is probably unnecessary since the comment here clearly specifies which versions are safe, but I suppose it can't hurt.
That said, the error message should probably mention both of the possible data loss issues, this and #316095: Raise PHP requirement to 5.2.12 for PostgreSQL only. Setting back to CNW. I leave it up to fiasco to decide how to merge these issues, but I'm +1 on the approach here.
Comment #17
lotyrin CreditAttribution: lotyrin commented#11: 515310-11-PHP_INT_MAX.patch queued for re-testing.
Comment #19
Crell CreditAttribution: Crell commentedComment #20
Josh Waihi CreditAttribution: Josh Waihi commented#11: 515310-11-PHP_INT_MAX.patch queued for re-testing.
Comment #21
Josh Waihi CreditAttribution: Josh Waihi commentedit passed, lets get it in.
Comment #22
Dries CreditAttribution: Dries commentedCrell, given that we didn't get an answer from fiasco, would you want me to commit this?
Comment #23
catchJosh Waihi == fiasco.
Comment #24
Crell CreditAttribution: Crell commentedIn concept I agree with this approach. My only issues with the most recent patch would be that it doesn't declare a visibility for the new test method (it defaults to public, but really we should specify that explicitly) and that it uses db_query() from within a DB class, but the installer is, I believe, an exception to that at the moment. (Maybe it needn't be, but for now it is.)
And as catch said, Josh == fiasco so for Postgres intricacies I defer to him.
Comment #25
Josh Waihi CreditAttribution: Josh Waihi commentedThe check this test is trying to prove will be no different if it were on another schema (should Drupal be installed on a non-standard PG schema). Thats a minor detail.
I you really want, we could put {} around the table name, but IMO, its not a huge deal.
fiasco.
Comment #26
Dries CreditAttribution: Dries commentedNot sure how I forgot that Josh is fiasco. Either way, I committed this patch to CVS HEAD. Thanks! :)
Comment #28
DrLou CreditAttribution: DrLou commentedHello All!
On a new install of 7.0-alpha6, on PostgreSQL (v9-beta2, if this matters), we are still seeing a seemingly? erroneous PHP version check:
We are currently running php 5.2.11...
Comment #29
gustavb CreditAttribution: gustavb commentedI am getting this warning with PHP 5.3.2-1ubuntu4.2 on 64-bit linux, even though I shouldn't according to the message. The reason is that the SQL insert fails with:
This is because
PHP_INT_MAX
is float(9.2233720368548E+18) on 64-bit systems (see http://php.net/manual/en/language.types.integer.php#language.types.integ...) and is erroneously quoted as a string when PDO uses it.So either this problem exists on 64-bit systems and the warning should be displayed but its text corrected, or it does not and the testing should be fixed.
Comment #30
tamasd CreditAttribution: tamasd commentedI am getting this warning on a 32 bit Ubuntu Lucid.
Comment #31
gustavb CreditAttribution: gustavb commented@Yorirou (#30), does your PostgreSQL log tell you anything (/var/log/postgresql/postgresql-8.4-main.log) when the check is performed?
Comment #32
tamasd CreditAttribution: tamasd commentedI think this is the relevant part of the log.
Comment #33
gustavb CreditAttribution: gustavb commentedSo the check fails when a too big value is inserted into a regular INT field.
But the bug report is about inserts into BIGINT fields, so something is wrong here.
Comment #34
Josh Waihi CreditAttribution: Josh Waihi commentedNice spotting! does this patch fix it for you?
Also a few whitespace clean ups too.
Comment #36
Josh Waihi CreditAttribution: Josh Waihi commentedah, git diff FAIL.
Comment #37
mradcliffeI ran into this too with MAMP 1.9 using PHP 5.3.2 and PostgreSQL 8.4.
I applied the patch, and visually confirmed that the error message did not come up anymore. I tried with both PHP 5.3.2 and PHP 5.2.13 in MAMP 1.9.
The code behind the patch looks good to me, and is fairly simple. I don't recall anything different with BIGINT in other versions of pg.
I think this can be RTBC once there's a review that still displays the message in a prior version of PHP.
sneak edit: somehow tag just got changed on my edit?
Comment #38
gustavb CreditAttribution: gustavb commented#34, For 32-bit systems this should work, but it will still fail with 64-bit systems (see #29). From what I understand PostgreSQL won't recognize the number expressed with E notation (
PHP_INT_MAX + 1
= 9.2233720368548E+18) as a numeric value when quoted as a string like PDO does. Unfortunately, even if it was expressed correctly, without quotes, it would fail as the maximum value for BIGINT is less thanPHP_INT_MAX + 1
on 64-bit systems. (9223372036854775807 < 9.2233720368548E+18).With PHP on 64-bit system:
And in PostgreSQL:
:(
Comment #39
gustavb CreditAttribution: gustavb commentedPer #38.
Comment #40
gustavb CreditAttribution: gustavb commentedMade the check conditional with
PHP_INT_MAX
≥ max allowed value for BIGINT to address #38. Also smuggled in some quoting style changes — should be more in line with the coding standards I assume.Comment #41
Damien Tournoud CreditAttribution: Damien Tournoud commentedLet's simply check the PHP version. We need to do it anyway, because there are other bugs in PHP < 5.2.7 that can prevent installation on PostgreSQL. See #862078: PDO coerceing empty strings to NULL when target is a Postgres bytea.
This is now a duplicate of the other issue.
Comment #42
shunting CreditAttribution: shunting commentedI have PHP 5.3.2 installed:
But I am still getting this error:
Comment #43
shunting CreditAttribution: shunting commentedI ran #38's check:
7.0-alpha6, on a 64-bit machine:
And:
Then, using this script, I discovered that my PHP_INT_MAX is 2147483647 (32-bit), which is a little short of the patch's 9223372036854775807 (64-bit). It seems that my macports install has an issue....
Comment #44
shunting CreditAttribution: shunting commentedContinued issues with installing a 64 bit PHP on OS X Server 10.4.11. A clean macports with +universal kept failing. MAMP and XAMPP are 32 bit. Compiling PostGres from source worked great, via here:
http://community.invisionpower.com/topic/292849-installing-postgresql-se...
However, compiling PHP 5.3.3 from source has not, via:
http://drewish.com/node/128
I run up against this bug, which has been marked "bogus" (not PHP) by the PHP developers, "Make fails dns.c:305":
http://bugs.php.net/bug.php?id=51706
If we need a 64 bit PHP to run PostGres, and that won't compile under some versions OS X, then that could be a problem?
Comment #45
Damien Tournoud CreditAttribution: Damien Tournoud commented@shunting: no, you don't need a 64bit PHP to run Drupal on PostgreSQL. The test here is bogus, and we are removing it in #862078: PDO coerceing empty strings to NULL when target is a Postgres bytea. You should help review this other issue.
Comment #46
shunting CreditAttribution: shunting commentedWell, that's a relief. Thanks for much for responding. Having torn my hair out, I was about to revert to MySQL, and abandon all the plpgsl functions I'd written... Anyhow, I learned a lot about compiler configuration!
(I should also say that whoever was monitoring the thread from http://bugs.php.net/bug.php?id=51706 didn't seem aware that OS X usage was very heavy in the Drupal community...
Comment #47
shunting CreditAttribution: shunting commentedThis is fixed; I left a note at the other issue.