php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #69457 pg_copy_from: order of table fields
Submitted: 2015-04-15 08:14 UTC Modified: -
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: okoanton at yandex dot ru Assigned:
Status: Open Package: PostgreSQL related
PHP Version: 5.6.7 OS: any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: okoanton at yandex dot ru
New email:
PHP Version: OS:

 

 [2015-04-15 08:14 UTC] okoanton at yandex dot ru
Description:
------------
pg_copy_from is a wrapper of postgresql syntax COPY test FROM stdin
But in postgresql people usually do this:

COPY test (field1, field2, field3) FROM stdin;

So I can describe fields and its order.

pg_copy_from without fields order is dangerous to use, because table can be changed by somebody.

Test script:
---------------
-- sql:
CREATE TABLE test (
   field1 int,
   field2 int
);


// php:
$rows = [1, 2];
pg_copy_from($db, $table_name, $rows);


-- sql
-- change order of fields
DROP TABLE test;
CREATE TABLE test (
   field2 int,
   field1 int
);


// php script without changes
$rows = [1, 2];
pg_copy_from($db, $table_name, $rows);

//it inserts data into wrong fields

Expected result:
----------------
a new parameter should be added to pg_copy_from to describe fields order 

Actual result:
--------------
result depends of table 

Patches

Pull Requests

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 14 00:01:26 2024 UTC