Обсуждение: Postgresql and scripting

Поиск
Список
Период
Сортировка

Postgresql and scripting

От
Jerome Lyles
Дата:
I'm trying to create and populate some study tables using a couple of scripts
that came with my 'SQL in 10 minutes' book. This is how I tried to run the
script to create and populate tables in a database named test:

test-# \i create.txt
psql:create.txt:1: ERROR:  syntax error at or near "" at character 1

Here is the top of the script:
------------------------------------------------------------
 - -   S a m s   T e a c h   Y o u r s e l f   S Q L   i n   1 0   M i n u t e
s

 - -   h t t p : / / w w w . f o r t a . c o m / b o o k s / 0 6 7 2 3 2 5 6 6
7 /

 - -   E x a m p l e   t a b l e   c r e a t i o n   s c r i p t s   f o r  Po
s t g r e S Q L .

------------------------------------------------------------



 - - - - - - - - - - - - - - - - - - - - - - - - -

 - -   C r e a t e   C u s t o m e r s   t a b l e

 - - - - - - - - - - - - - - - - - - - - - - - - -

 C R E A T E   T A B L E   C u s t o m e r s

 (

     c u s t _ i d             c h a r ( 1 0 )     N O T   N U L L   ,

     c u s t _ n a m e         c h a r ( 5 0 )     N O T   N U L L   ,

     c u s t _ a d d r e s s   c h a r ( 5 0 )     ,

     c u s t _ c i t y         c h a r ( 5 0 )     ,

     c u s t _ s t a t e       c h a r ( 5 )       ,

     c u s t _ z i p           c h a r ( 1 0 )     ,

     c u s t _ c o u n t r y   c h a r ( 5 0 )     ,

     c u s t _ c o n t a c t   c h a r ( 5 0 )     ,

     c u s t _ e m a i l       c h a r ( 2 5 5 )

 ) ;

Can someone tell me what's going wrong here, why am I getting this error
message?
Thanks,
Jerome

Re: Postgresql and scripting

От
Devrim GUNDUZ
Дата:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Hi,

On Tue, 7 Sep 2004, Jerome Lyles wrote:

> I'm trying to create and populate some study tables using a couple of scripts
> that came with my 'SQL in 10 minutes' book. This is how I tried to run the
> script to create and populate tables in a database named test:
>
> test-# \i create.txt
> psql:create.txt:1: ERROR:  syntax error at or near "" at character 1
>
> Here is the top of the script:
> ------------------------------------------------------------
> - -   S a m s   T e a c h   Y o u r s e l f   S Q L   i n   1 0   M i n u t e
> s

The single dash must be --. PostgreSQL treats -- as the comment lines.
i.e.:

- --------------
- -- Sams Teach ...
- --

Anyway, IMHO you should directly begin with the following line:

> CREATE TABLE customers
...

The lines above this one are useless comments.

Regards,
- --
Devrim GUNDUZ
devrim~gunduz.org                devrim.gunduz~linux.org.tr
             http://www.tdmsoft.com
             http://www.gunduz.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFBPZxKtl86P3SPfQ4RAgMbAJ9m3zTRnZiKtlmn0LI3MgjMDP/CdACeJ2rp
fR/DMnCjNbPLEsSDIampUJk=
=OexA
-----END PGP SIGNATURE-----

Re: Postgresql and scripting

От
John DeSoi
Дата:
On Sep 7, 2004, at 7:24 AM, Jerome Lyles wrote:

> test-# \i create.txt
> psql:create.txt:1: ERROR:  syntax error at or near "" at character 1
>
> Here is the top of the script:
> ------------------------------------------------------------
>  - -   S a m s   T e a c h   Y o u r s e l f   S Q L   i n   1 0   M i
> n u t e
>

It seems that your file might be in unicode (utf-16) since it appears
there is whitespace after every character. Check your editor settings
and resave the file.

Best,

John DeSoi, Ph.D.


Re: Postgresql and scripting

От
Jerome Lyles
Дата:
On Tuesday 07 September 2004 01:50 am, John DeSoi wrote:
> On Sep 7, 2004, at 7:24 AM, Jerome Lyles wrote:
> > test-# \i create.txt
> > psql:create.txt:1: ERROR:  syntax error at or near "" at character 1
> >
> > Here is the top of the script:
> > ------------------------------------------------------------
> >  - -   S a m s   T e a c h   Y o u r s e l f   S Q L   i n   1 0   M i
> > n u t e
>
> It seems that your file might be in unicode (utf-16) since it appears
> there is whitespace after every character. Check your editor settings
> and resave the file.
>
> Best,
>
> John DeSoi, Ph.D.
Right now it's in unicode (utf-8), switching between utf 8 and sixteen has no
effect on the spaces between letters.  Tried iso 8859-1 and iso 8859-15 but
the editor window was empty for these encodings.

Can someone point me to a sed or shell script that I can use on a text file to
remove the whitespace between the letters in the words only?   Here is the
top of the script file as it stands now:

- -   C r e a t e   C u s t o m e r s   t a b l e



 C R E A T E   T A B L E   C u s t o m e r s

 (

     c u s t _ i d             c h a r ( 1 0 )     N O T   N U L L   ,

     c u s t _ n a m e         c h a r ( 5 0 )     N O T   N U L L   ,

     c u s t _ a d d r e s s   c h a r ( 5 0 )     ,

     c u s t _ c i t y         c h a r ( 5 0 )     ,

     c u s t _ s t a t e       c h a r ( 5 )       ,

     c u s t _ z i p           c h a r ( 1 0 )     ,

     c u s t _ c o u n t r y   c h a r ( 5 0 )     ,

     c u s t _ c o n t a c t   c h a r ( 5 0 )     ,

     c u s t _ e m a i l       c h a r ( 2 5 5 )

 ) ;


Re: Postgresql and scripting

От
Alvaro Herrera
Дата:
On Tue, Sep 07, 2004 at 01:33:08PM -1000, Jerome Lyles wrote:
> On Tuesday 07 September 2004 01:50 am, John DeSoi wrote:
> > On Sep 7, 2004, at 7:24 AM, Jerome Lyles wrote:
> > > test-# \i create.txt
> > > psql:create.txt:1: ERROR:  syntax error at or near "" at character 1
> > >
> > > Here is the top of the script:
> > > ------------------------------------------------------------
> > >  - -   S a m s   T e a c h   Y o u r s e l f   S Q L   i n   1 0   M i
> > > n u t e
> >
> > It seems that your file might be in unicode (utf-16) since it appears
> > there is whitespace after every character. Check your editor settings
> > and resave the file.

> Right now it's in unicode (utf-8), switching between utf 8 and sixteen has no
> effect on the spaces between letters.  Tried iso 8859-1 and iso 8859-15 but
> the editor window was empty for these encodings.

Did you try using recode?

recode utf16..iso8859-15 filename

Of course, just changing the encoding setting in the editor does not
automatically recode the file, does it?

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"Ni aun el genio muy grande llegaría muy lejos
si tuviera que sacarlo todo de su propio interior" (Goethe)


Re: Postgresql and scripting

От
Oliver Elphick
Дата:
On Wed, 2004-09-08 at 00:33, Jerome Lyles wrote:
...
> Can someone point me to a sed or shell script that I can use on a text file to
> remove the whitespace between the letters in the words only?   Here is the
> top of the script file as it stands now:
>
> - -   C r e a t e   C u s t o m e r s   t a b l e
>

$ echo '- -   C r e a t e   C u s t o m e r s   t a b l e' |
    sed -e 's/\([^ ]\) \([^ ]\)/\1\2/g' -e 's/\([^ ]\) \([^ ]\)/\1\2/g' -e 's/  */ /g'
-- Create Customers table

--
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
                 ========================================
     "Put on the whole armor of God, that ye may be able to
      stand against the wiles of the devil."
                                        Ephesians 6:11


Re: Postgresql and scripting

От
Jerome Lyles
Дата:
On Tuesday 07 September 2004 10:22 pm, Dorward villaruz wrote:
> hi!
>
> try this in commandline i assume you save the file in sams.txt
> final file will be sams2.txt
>
> cat sams.txt | sed -e 's/  /@@/g' -e 's/ //g' -e 's/@@/ /g' > sams2.txt
>
> or put this in a script say convert.sh
>
> script start:
> #!/bin/bash
> cat $1 | sed -e 's/  /@@/g' -e 's/ //g' -e 's/@@/ /g' > $2
> script end:
>
> how to use?
>
> convert.sh <input file>  <output file>
>
> best regards,
> wardy
>
Thank you for this.  I've spent a few hours today searching and experimenting
to produce this code.  I can almost understand the sed command.  Everything
between the quotes is the action to be taken.  The 's' is for substitution,
the / / is the whitespace to be replaced, the/@@/ is what the whitespace is
replaced with but I don't know what the @@ stands for, the g means it's
applied globally.  I think what I just said is wrong because I have no clue
why the second and third substitution are there.  And finally the output is
directed to $2.  I'll have to wait until tomorrow evening to play with it.  I
look forward to it.
thanks,
Jerome

Re: Postgresql and scripting

От
Greg Stark
Дата:
Jerome Lyles <susemail@hawaii.rr.com> writes:

> the/@@/ is what the whitespace is replaced with but I don't know what the @@
> stands for,

It doesn't stand for anything, it just means replace with "@@". Now look again
at the second and third substitution...

--
greg