Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Bugs

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 09:18 AM
Oliver Elphick
 
Posts: n/a
Default Problem with COPY in 8.0.3

Pg 8.0.3 (Debian package) on AMD64, linux 2.6.12

I am importing a table using COPY. The data is tab-delimited. COPY
seems to be putting the data for one field into the preceding field,
which should contain the empty string.

Here is the data, with tabs indicated by ^I and end of line by $:
67829^I22058^IX378^I10 FEB 2004^I10 FEB 2004^I0.000^I5411^I15498-00^IGBP^I0.00^It^It^I\N^I\N^I\N^I\N^I\N^I\N^I10 FEB 2004^I60^I0.00^I0.00^I0^I0.00^ICarton^I570.000^I0. 000^I^ICIF-MONTREAL/ACT 30-DAYS^I^IChemist\'s sundries^IAMG MEDICAL;5411;MONTREAL;1-60;^ITHAMESPORT^ISEA/ALLIANCE^ICA^IGB^IMAIREAD BOYCE, DIRECTOR^I1$

the command used to fill the table is:
COPY export_invoice FROM '/usr1/avdumps/dbdump.exportinvoice';

and here is how COPY has rendered it:
bray=# select * from export_invoice where invno = 67829;
invno | customer | account | invdate | taxpoint | discount | ordno | custref | currency | carriage | printed | assigned | customer_ean | location_ean | exchange_rate | grpid | postcode | grn | orderdate | packages | packing | other | other_desc | insurance | pack_desc | kilos | nett | dimensions | terms | bank | goods | marks | port | transport | destination | origin | auth | copies
-------+----------+---------+------------+------------+----------+-------+----------+----------+----------+---------+----------+--------------+--------------+---------------+-------+----------+-----+------------+----------+---------+-------+------------+-----------+-----------+---------+-------+--------------------------+-------+------+--------------------+---------------------------------+------------+--------------+-------------+--------+-------------------------+--------
67829 | 22058 | X378 | 2004-02-10 | 2004-02-10 | 0.000 | 5411 | 15498-00 | GBP | 0.00 | t | t | | | | | | | 2004-02-10 | 60 | 0.00 | 0.00 | 0 | 0.00 | Carton | 570.000 | 0.000 | CIF-MONTREAL/ACT 30-DAYS | | | Chemist's sundries | AMG MEDICAL;5411;MONTREAL;1-60; | THAMESPORT | SEA/ALLIANCE | CA | GB | MAIREAD BOYCE, DIRECTOR | 1
(1 row)

The problem is seen in columns 28 and 29 (dimensions and terms). The
data for terms is in dimensions, which ought to contain the empty
string.

Table definitions:
Table "prod.export_invoice"
Column | Type | Modifiers
---------------+-----------------------+--------------------------------------
invno | integer | not null
customer | character varying(10) | not null
account | character varying(8) | not null
invdate | date | not null default ('now'::text)::date
taxpoint | date | not null default ('now'::text)::date
discount | numeric(5,3) | not null default 0.0
ordno | integer | not null
custref | text | not null default 'NONE'::text
currency | character(3) | not null
carriage | numeric(10,2) | not null default 0.00
printed | boolean | not null default false
assigned | boolean | not null default false
customer_ean | character varying(13) |
location_ean | character varying(13) |
exchange_rate | numeric(10,4) |
grpid | character varying(2) |
postcode | character varying(10) |
grn | character varying(20) |
orderdate | date |
packages | integer | not null default 1
packing | numeric(12,2) |
other | numeric(12,2) |
other_desc | text |
insurance | numeric(12,2) |
pack_desc | text |
kilos | numeric(12,3) |
nett | numeric(12,3) |
dimensions | text |
terms | text |
bank | text |
goods | text |
marks | text |
port | text |
transport | text |
destination | character(2) |
origin | character(2) | not null default 'GB'::bpchar
auth | text |
copies | integer | not null default 1
....indexes and constraints omitted...





---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 09:18 AM
Oliver Elphick
 
Posts: n/a
Default Re: Problem with COPY in 8.0.3

On Wed, 2005-10-12 at 09:09 +0100, Oliver Elphick wrote:
> Pg 8.0.3 (Debian package) on AMD64, linux 2.6.12
>
> I am importing a table using COPY. The data is tab-delimited. COPY
> seems to be putting the data for one field into the preceding field,
> which should contain the empty string.


To follow up on this, there seems to be a general problem that COPY did
not use the same column order as a default display for this particular
table. The table had just been created and had not been subjected to
alterations.

I got round the problem by specifying the column list to the COPY
command.

--
Oliver Elphick olly@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
Do you want to know God? http://www.lfix.co.uk/knowing_god.html


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-10-2008, 09:18 AM
Tom Lane
 
Posts: n/a
Default Re: Problem with COPY in 8.0.3

Oliver Elphick <olly@bray-healthcare.com> writes:
> Pg 8.0.3 (Debian package) on AMD64, linux 2.6.12
> I am importing a table using COPY. The data is tab-delimited. COPY
> seems to be putting the data for one field into the preceding field,
> which should contain the empty string.


Can't reproduce that here, under either 8.0 or CVS tip. Are you sure
you aren't making some silly mistake, like copying from the wrong file?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-10-2008, 09:18 AM
Oliver Elphick
 
Posts: n/a
Default Re: Problem with COPY in 8.0.3

On Wed, 2005-10-12 at 13:52 -0400, Tom Lane wrote:
> Oliver Elphick <olly@bray-healthcare.com> writes:
> > Pg 8.0.3 (Debian package) on AMD64, linux 2.6.12
> > I am importing a table using COPY. The data is tab-delimited. COPY
> > seems to be putting the data for one field into the preceding field,
> > which should contain the empty string.

>
> Can't reproduce that here, under either 8.0 or CVS tip. Are you sure
> you aren't making some silly mistake, like copying from the wrong file?


No. This is a regular (nightly) scripted dump, which drops and rebuilds
the entire database, and the right data is going into the file (I only
showed one line out of 300+). But in this particular case, the column
order was wrong. I should add that the table inherits from another one,
but the swapped columns are a long way into the extra columns specific
to this table.

I've changed the script to fix it, so its not a big issue for me, but I
first noticed it several days ago, so it's not a one off occurrence.

Oliver
--
Oliver Elphick olly@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
Do you want to know God? http://www.lfix.co.uk/knowing_god.html


---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-10-2008, 09:18 AM
Michael Fuhr
 
Posts: n/a
Default Re: Problem with COPY in 8.0.3

On Wed, Oct 12, 2005 at 09:09:05AM +0100, Oliver Elphick wrote:
> Pg 8.0.3 (Debian package) on AMD64, linux 2.6.12
>
> I am importing a table using COPY. The data is tab-delimited. COPY
> seems to be putting the data for one field into the preceding field,
> which should contain the empty string.


I couldn't duplicate this in 8.0.4 on either FreeBSD or Solaris.
I created a table using your definition and put the data into a
file, converting ^I to tab and removing the trailing $.

perl -lne 'if (/^67829/) {s/\^I/\t/g; s/\$$//; print}' msg.txt > data.txt

I used COPY to load data.txt; SELECT then returned the following:

\x
SELECT * FROM export_invoice;
....
kilos | 570.000
nett | 0.000
dimensions |
terms | CIF-MONTREAL/ACT 30-DAYS
bank |
goods | Chemist's sundries
....

I see a few COPY fixes in pgsql-committers, although I don't know
if any would affect the behavior you're seeing. Have you tried
8.0.4? Have you done any tests with a freshly-created table? Have
you executed any ALTER TABLE statements on export_invoice? I don't
know if COPY could have problems with that; I'm just wondering what
might be different between your environment and mine, aside from
the PostgreSQL version and operating system.

On another note, regarding the following:

> invdate | date | not null default ('now'::text)::date
> taxpoint | date | not null default ('now'::text)::date


Are you sure you want 'now'::text as a default, considering the
warning against it?

http://www.postgresql.org/docs/8.0/i...TETIME-CURRENT

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-10-2008, 09:18 AM
Michael Fuhr
 
Posts: n/a
Default Re: Problem with COPY in 8.0.3

On Wed, Oct 12, 2005 at 07:08:20PM +0100, Oliver Elphick wrote:
> I should add that the table inherits from another one, but the
> swapped columns are a long way into the extra columns specific to
> this table.


Could you post the table definitions?

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-10-2008, 09:18 AM
Michael Fuhr
 
Posts: n/a
Default Re: Problem with COPY in 8.0.3

On Wed, Oct 12, 2005 at 12:19:41PM -0600, Michael Fuhr wrote:
> On Wed, Oct 12, 2005 at 07:08:20PM +0100, Oliver Elphick wrote:
> > I should add that the table inherits from another one, but the
> > swapped columns are a long way into the extra columns specific to
> > this table.

>
> Could you post the table definitions?


BTW, I meant the CREATE TABLE statements, not the \d output.

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-10-2008, 09:18 AM
Oliver Elphick
 
Posts: n/a
Default Re: Problem with COPY in 8.0.3

On Wed, 2005-10-12 at 12:37 -0600, Michael Fuhr wrote:
> On Wed, Oct 12, 2005 at 12:19:41PM -0600, Michael Fuhr wrote:
> > On Wed, Oct 12, 2005 at 07:08:20PM +0100, Oliver Elphick wrote:
> > > I should add that the table inherits from another one, but the
> > > swapped columns are a long way into the extra columns specific to
> > > this table.

> >
> > Could you post the table definitions?

>
> BTW, I meant the CREATE TABLE statements, not the \d output.
>

Here it is:

CREATE TABLE invoice
(
invno INTEGER ,
customer VARCHAR(10) NOT NULL,
account VARCHAR(8) NOT NULL,
invdate DATE NOT NULL
DEFAULT CURRENT_DATE,
taxpoint DATE NOT NULL
DEFAULT CURRENT_DATE,
discount DECIMAL(5,3) NOT NULL DEFAULT 0.0
CHECK (discount >= -50.0:ECIMAL(5,3) AND
discount <= 50.0:ECIMAL(5,3)),
ordno INTEGER,
custref TEXT NOT NULL DEFAULT 'NONE',
currency CHAR(3) NOT NULL,
carriage DECIMAL(10,2) NOT NULL DEFAULT 0.00,
printed BOOLEAN NOT NULL DEFAULT 'f',
assigned BOOLEAN NOT NULL DEFAULT 'f',
customer_ean VARCHAR(13),
location_ean VARCHAR(13),
exchange_rate DECIMAL(10,4),
grpid VARCHAR(2),
postcode VARCHAR(10),
grn VARCHAR(20),
orderdate DATE CONSTRAINT "sane order date"
CHECK(orderdate <= invdate),
CONSTRAINT "EDI fields" CHECK ((customer_ean IS NULL AND location_ean IS NULL) OR (customer_ean IS
NOT NULL AND customer_ean != '' AND location_ean IS NOT NULL AND location_ean != '')),
CONSTRAINT "foreign exchange" CHECK ((currency = 'GBP' AND exchange_rate is NULL) OR (currency != 'GBP' AND exchange_rate IS NOT NULL AND exchange_rate > 0.))
,
PRIMARY KEY (invno),
CONSTRAINT invoice_list_fkey
FOREIGN KEY (invno) REFERENCES invoice_list (invno)
ON UPDATE CASCADE
ON DELETE RESTRICT
INITIALLY DEFERRED,
CONSTRAINT customer_accounts_fkey
FOREIGN KEY (customer, account)
REFERENCES customer_accounts (customer, account)
ON UPDATE CASCADE
ON DELETE RESTRICT
INITIALLY DEFERRED,
CONSTRAINT customer_fkey
FOREIGN KEY (customer)
REFERENCES customer (id)
ON UPDATE CASCADE
ON DELETE RESTRICT
DEFERRABLE,
CONSTRAINT authorised_currency_fkey
FOREIGN KEY (currency)
REFERENCES authorised_currency (currency)
ON UPDATE CASCADE
ON DELETE RESTRICT
DEFERRABLE,
CONSTRAINT customer_group_fkey
FOREIGN KEY (grpid)
REFERENCES customer_group (id)
ON UPDATE CASCADE
ON DELETE RESTRICT
DEFERRABLE

);

CREATE TABLE export_invoice
(
packages INTEGER NOT NULL
CHECK (packages > 0)
DEFAULT 1,
packing NUMERIC(12,2),
other NUMERIC(12,2),
other_desc TEXT,
insurance NUMERIC(12,2),
pack_desc TEXT,
kilos NUMERIC(12,3),
nett NUMERIC(12,3),
dimensions TEXT,
terms TEXT,
bank TEXT,
goods TEXT,
marks TEXT,
port TEXT,
transport TEXT,
destination CHAR(2) CONSTRAINT destination
REFERENCES country (id)
ON UPDATE CASCADE
ON DELETE NO ACTION,
origin CHAR(2) NOT NULL DEFAULT 'GB'
CONSTRAINT origin
REFERENCES country (id)
ON UPDATE CASCADE
ON DELETE NO ACTION,
auth TEXT,
copies INTEGER NOT NULL DEFAULT 1
,
PRIMARY KEY (invno),
CONSTRAINT invoice_list_fkey
FOREIGN KEY (invno) REFERENCES invoice_list (invno)
ON UPDATE CASCADE
ON DELETE RESTRICT
INITIALLY DEFERRED,
CONSTRAINT customer_accounts_fkey
FOREIGN KEY (customer, account)
REFERENCES customer_accounts (customer, account)
ON UPDATE CASCADE
ON DELETE RESTRICT
INITIALLY DEFERRED,
CONSTRAINT customer_fkey
FOREIGN KEY (customer)
REFERENCES customer (id)
ON UPDATE CASCADE
ON DELETE RESTRICT
DEFERRABLE,
CONSTRAINT authorised_currency_fkey
FOREIGN KEY (currency)
REFERENCES authorised_currency (currency)
ON UPDATE CASCADE
ON DELETE RESTRICT
DEFERRABLE,
CONSTRAINT customer_group_fkey
FOREIGN KEY (grpid)
REFERENCES customer_group (id)
ON UPDATE CASCADE
ON DELETE RESTRICT
DEFERRABLE

)
INHERITS (invoice)
;

ALTER TABLE export_invoice ALTER COLUMN ordno SET NOT NULL;
CREATE INDEX export_inv_customer_ix ON export_invoice(customer);
CREATE INDEX export_inv_account_ix ON export_invoice(account);
CREATE INDEX export_inv_date_ix ON export_invoice(invdate);




--
Oliver Elphick olly@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
Do you want to know God? http://www.lfix.co.uk/knowing_god.html


---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-10-2008, 09:18 AM
Michael Fuhr
 
Posts: n/a
Default Re: Problem with COPY in 8.0.3

On Wed, Oct 12, 2005 at 08:23:15PM +0100, Oliver Elphick wrote:
> On Wed, 2005-10-12 at 12:13 -0600, Michael Fuhr wrote:
> > On another note, regarding the following:
> >
> > > invdate | date | not null default ('now'::text)::date
> > > taxpoint | date | not null default ('now'::text)::date

> >
> > Are you sure you want 'now'::text as a default, considering the
> > warning against it?

>
> I actually use CURRENT_DATE; that is what the system turns it into.


Ah yes, I see that now. I generally use now(), so I hadn't noticed
that CURRENT_DATE and CURRENT_TIMESTAMP become 'now', whereas only
a literal 'now' is expanded at create time:

CREATE TABLE foo (
d1 date NOT NULL DEFAULT now(),
d2 date NOT NULL DEFAULT CURRENT_DATE,
d3 date NOT NULL DEFAULT 'now'
);

\d foo
Table "public.foo"
Column | Type | Modifiers
--------+------+--------------------------------------
d1 | date | not null default now()
d2 | date | not null default ('now'::text)::date
d3 | date | not null default '2005-10-12'::date

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-10-2008, 09:18 AM
Michael Fuhr
 
Posts: n/a
Default Re: Problem with COPY in 8.0.3

On Wed, Oct 12, 2005 at 08:17:23PM +0100, Oliver Elphick wrote:
> On Wed, Oct 12, 2005 at 12:19:41PM -0600, Michael Fuhr wrote:
> > Could you post the table definitions?

>
> Here it is:


I created the tables you posted (sans foreign key constraints because
you didn't include the referenced tables) and loaded the data from
your previous post into an 8.0.4 server on FreeBSD 4.11-STABLE.
Here's what I got; it looks correct around the columns you report
having trouble with:

\x
SELECT * FROM export_invoice;
-[ RECORD 1 ]-+--------------------------------
invno | 67829
customer | 22058
account | X378
invdate | 2004-02-10
taxpoint | 2004-02-10
discount | 0.000
ordno | 5411
custref | 15498-00
currency | GBP
carriage | 0.00
printed | t
assigned | t
customer_ean |
location_ean |
exchange_rate |
grpid |
postcode |
grn |
orderdate | 2004-02-10
packages | 60
packing | 0.00
other | 0.00
other_desc | 0
insurance | 0.00
pack_desc | Carton
kilos | 570.000
nett | 0.000
dimensions |
terms | CIF-MONTREAL/ACT 30-DAYS
bank |
goods | Chemist's sundries
marks | AMG MEDICAL;5411;MONTREAL;1-60;
port | THAMESPORT
transport | SEA/ALLIANCE
destination | CA
origin | GB
auth | MAIREAD BOYCE, DIRECTOR
copies | 1

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:19 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510