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.
@Rhim appears to be correct - [you've hit what was assumed to be a compiler bug](http://www.postgresql.org/message-id/17948.1365090217@sss.pgh.pa.us). You might want to update to the latest gcc packages then `make clean`, re-run `configure` with `CFLAGS="-O1"` as an argument, and then re-compile.

BTW, this suggests that you are compiling PostgreSQL 8.4 or older as `pg_sync_pg_database` doesn't appear in 9.0 or newer. You must also be compiling on a newer host. As PostgreSQL 8.4 will soon be end-of-life and unsupported, this is probably not a good idea.

It also suggests you've compiled your own version rather than using packages. You should use <http://apt.postgresql.org/> rather than compiling your own unless you have a good specific reason.