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 Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
48 + 23 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 11:01:29 2024 UTC