Question: I am trying to get a "datetime" from a csv file and insert it into MySql Database. What am I doing wrong? Thanks in advance!

```
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) 
            {
                $date = new Datetime();
                $this->date->format('Y-d-m H:i:s', ($data[3]));

                $sql = "INSERT INTO logs(ID, User, Flag, Date) values('$data[0]', '$data[1]', '$data[2]', '$data[3]')";
                $insert = $this->dataBase->getData($sql);

```

Answer: 
I ran into the same problem after compiling postgresql 8.1.4 with gcc 4.9.3.

The problem seems to be the way postgres uses to represent variable length arrays:

```
typedef struct
{
    int32       size;           /* these fields must match ArrayType! */
    int         ndim;
    int         flags;
    Oid         elemtype;
    int         dim1;
    int         lbound1;
    int2        values[1];      /* VARIABLE LENGTH ARRAY */
} int2vector;                   /* VARIABLE LENGTH STRUCT */

```

In some cases, for loops accessing 'values', GCC assumes that they will do one iteration at most. Loops like the one below (extracted from postgres's source code):

```
ii->ii_NumIndexAttrs = numKeys;
for (i = 0; i < numKeys; i++)
    ii->ii_KeyAttrNumbers[i] = indexStruct->indkey.values[i];

```

might end up being reduced to something like:

```
ii->ii_NumIndexAttrs = numKeys;
if (numKeys)
    ii->ii_KeyAttrNumbers[0] = indexStruct->indkey.values[0];

```

as deduced by looking at the assembler generated for it:

```
.L161:
    testl   %r12d, %r12d
    movl    %r12d, 4(%rbx)
    jle .L162
    movzwl  40(%r13), %eax
    movw    %ax, 8(%rbx)
.L162:

```

The problem went away after re-compiling postgres with that optimization disabled by using -fno-aggressive-loop-optimizations.
I ran in the same problem.
I have a production database in release 9.1 of Postgres and i must reinstall it on a new host.
I’m trying this on a Centos8 and a Debian11
gcc version 8.5.0

I used the CFLAGS environment variable :

```
export CFLAGS=-fno-aggressive-loop-optimizations

```

Others -O1 or clang didn’t work at all.
Then, everything worked perfect :

```
./configure --enable-debug  --enable-depend --prefix=$PG_HOME
gmake -j 5 world 
gmake check

```

No more errors