Thread: Data format problem

Data format problem

From
"Verbus M. Counts"
Date:
Greetings,

The following is a problem I am having:

#!/bin/bash
#
# Demo script for postgreSQL
#
uname  -a

psql -V

dropdb testdb

createdb testdb

echo "create table titles"
psql testdb <<EOF
create table titles
    (title_id char(6) not null,
    title text not null,
    type char(12) null,
    pub_id char(4) null,
    price float8 null,
    advance numeric(12,2) null,
    num_sold int null,
    notes varchar(200) null,
    pubdate datetime null,
    contract int not null);
EOF

echo "insert into titles"
psql testdb <<EOF
insert into titles
values ('BU1111',
'Cooking with Computers: Surreptitious Balance Sheets',
'business',
'1389',
$11.95,
$5000.00,
3876,
'Helpful hints on how to use your electronic resources to the best
advantage.', '06/09/88', 1);

insert into titles
values ('MC2222',
'Silicon Valley Gastronomic Treats',
'mod_cook',
'0877',
$19.99,
$0.00,
2032,
'Favorite recipes for quick, easy, and elegant meals, tried and tested
by people who never have time to eat, let alone cook.',
'06/09/89', 1);
EOF


-----------------------------------------------------------------
When I run the above:

Linux aossofca.com 2.4.7-10enterprise #1 SMP Thu Sep 6 16:48:20 EDT 2001
i686 unknown
psql (PostgreSQL) 7.1.3
contains readline, history, multibyte support
Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
Portions Copyright (c) 1996 Regents of the University of California
Read the file COPYRIGHT or use the command \copyright to see the
usage and distribution terms.
DROP DATABASE
CREATE DATABASE
create table titles
CREATE
insert into titles
INSERT 59101 1
ERROR:  parser: parse error at or near "."

When I change the $0.00 to $1.00 all works well????????????

--
Regards,
Verbus M. Counts
Director R & D
Advanced Open Source Solutions, Inc.
10 South Grant Street
Roseville, CA 95678
916-765-1624


Re: Data format problem

From
Tom Lane
Date:
"Verbus M. Counts" <verbus@sonicisp.net> writes:
> psql testdb <<EOF
> insert into titles
> values ('BU1111',
> 'Cooking with Computers: Surreptitious Balance Sheets',
> 'business',
> '1389',
> $11.95,
> $5000.00,
> 3876,
> 'Helpful hints on how to use your electronic resources to the best
> advantage.', '06/09/88', 1);

Those dollar signs should not be there; they are not noise, as you
seem to think.  I suspect that your shell script interpreter is
substituting something for them.

            regards, tom lane

Re: Data format problem

From
Stephan Szabo
Date:
> echo "insert into titles"
> psql testdb <<EOF
> insert into titles
> values ('BU1111',
> 'Cooking with Computers: Surreptitious Balance Sheets',
> 'business',
> '1389',
> $11.95,
> $5000.00,
> 3876,
> 'Helpful hints on how to use your electronic resources to the best
> advantage.', '06/09/88', 1);
>
> insert into titles
> values ('MC2222',
> 'Silicon Valley Gastronomic Treats',
> 'mod_cook',
> '0877',
> $19.99,
> $0.00,
> 2032,
> 'Favorite recipes for quick, easy, and elegant meals, tried and tested
> by people who never have time to eat, let alone cook.',
> '06/09/89', 1);
> EOF

> When I change the $0.00 to $1.00 all works well????????????

I think you don't want those $ in front of the amounts.

Try doing a
cat <<EOF
<data from above>
EOF

and seeing what it gives you.  My guess is that it's replace
the $<n> with something.  In the case of $0 it's probably the program
name.