The php code is bellow.
$cc='create table mydataI(net) as VALUES (-20.12::double precision)';
$db->query($cc) or die('<br><br><br> pos02:'.$db->lasterror.'<br>'.nl2br($cc));
The error is as follows:
pos02:ERROR: 42601: syntax error at or near "precision" LINE 1: ...e table mydataI(net) as VALUES (-20.12::numeric precision) ^ LOCATION: scanner_yyerror, scan.l:1081 create table mydataI(net) as VALUES (-20.12::double precision)
if I use instead:
$cc='create table mydataI(net) as VALUES (-20.12)';
$db->query($cc) or die('<br><br><br> pos02:'.$db->lasterror.'<br>'.nl2br($cc));
The php code runs correctly
When I copy paste the initial string to phpAdmin4 the code is run correctly by the postgres interpreter.
I tried to using php the code:
$cc='create table mydataI(net) as VALUES (-20.12::double),-15.01);';
$db->query($cc) or die('<br><br><br>
And this works ( it seems that the php "pipe" somehow interprets and converts some parts - in this case erroneously ).
The full code that I use has a file 'mydataQuery.php' that connects the $db to the database.
<?php
require 'mydataQuery.php';
global $db; //the database is connected from other code
$cc="drop table if exists mydataI cascade;";
$db->query($cc) or die('<br><br><br> pos01:'.$db->lasterror.'<br>'.$cc); echo "Dropped table<br>"; $cc="create table mydataI(aa) as VALUES (1.1 double precision),(1.2::double precision);"; $db->query($cc) or die('<br><br><br> pos02:'.$db->lasterror.'<br>'.nl2br($cc)); echo "Created table<br>"; ?>
pos01:'.$db->lasterror.'
'.$cc); echo "Dropped table
"; $cc="create table mydataI(aa) as VALUES (1.1 double precision),(1.2::double precision);"; $db->query($cc) or die('
pos02:'.$db->lasterror.'
'.nl2br($cc)); echo "Created table
"; ?> – George Kourtis Aug 19 '22 at 14:28