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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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: Thu Nov 21 13:01:29 2024 UTC