Обсуждение: Importing/Exporting

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

Importing/Exporting

От
Nathan Hill
Дата:
I am new to doing DBA activities.  I am trying to
write a bash script that will copy the value of a
specific field  within a table in a postgres database
on one server and import the value of that field into
a table in a mysql database on a separate server.  I
am not real familiar with sql statements yet so I was
hoping that someone could give me some advice.

My initial thoughts would be to copy the output of the
select statement to a file, copy the value that I need
from the file to a variable, then import that variable
into the appropriate field in the mysql database.
Where I am getting hung up is trying to export the
value of a specific field to a file.

Is there an easier way of doing this?

Thanks,

Nathan Hill

__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com

Re: Importing/Exporting

От
Oliver Elphick
Дата:
On Wed, 2002-07-31 at 22:39, Nathan Hill wrote:
> I am new to doing DBA activities.  I am trying to
> write a bash script that will copy the value of a
> specific field  within a table in a postgres database
> on one server and import the value of that field into
> a table in a mysql database on a separate server.  I
> am not real familiar with sql statements yet so I was
> hoping that someone could give me some advice.
>
> My initial thoughts would be to copy the output of the
> select statement to a file, copy the value that I need
> from the file to a variable, then import that variable
> into the appropriate field in the mysql database.
> Where I am getting hung up is trying to export the
> value of a specific field to a file.
>
> Is there an easier way of doing this?


If you want one value only, you can just store it in a variable rather
than a file:

  myvar=`psql -d mydatabase -A -t -c "SELECT field1 FROM table1 WHERE field2 = 'x' LIMIT 1"`
  mysql -e "UPDATE table2 SET field2 = '$myvar' ..." ...

--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight, UK
http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "And why call ye me, Lord, Lord, and do not the things
      which I say?"                   Luke 6:46