473,699 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Postgres COPY Command with python 2.3 pg

Hi to all,

can some one point me to the correct way, how to use PostgreSQLs "COPY" feature
from within python ?

What i want to do is:

connect
start transaction
drop current tablecontens
copy new content from STDIN # file need more privileged user rights
commit transaction

using psql it works fine, but i dont know how to get it working in python.
Ive already made the calls but the changes never apper, and no error.
my suggestion was, that "db.query("inpu t|input|input") doesnt work as STDIN for
the Database, and i tryed db.putline(.... ) but no success.

Kind regards for any help
Michael Lang

Jul 18 '05 #1
3 2938
Michael Lang wrote:
using psql it works fine, but i dont know how to get it working in python.
Ive already made the calls but the changes never apper, and no error.


Which Postgres module are you using? I had the exct same problem when I
first started using pyPgSQL, until I figured out that I needed to do:

db = PgSQL.connect(D SN)
db.autocommit = 1
con = db.cursor()

In my code.
Jul 18 '05 #2
On 2005-02-15, @(none) <""> wrote:
Michael Lang wrote:
using psql it works fine, but i dont know how to get it working in python.
Ive already made the calls but the changes never apper, and no error.
Which Postgres module are you using? I had the exct same problem when I
first started using pyPgSQL, until I figured out that I needed to do:

db = PgSQL.connect(D SN)
db.autocommit = 1
con = db.cursor()


Hi,

im using PostgreSQL RPM from Fedora Core3
$ rpm -q postgresql-python
postgresql-python-7.4.6-1.FC3.2

code looks like
Python 2.3.4 (#1, Oct 26 2004, 16:42:40)
[GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
import pg
db = pg.DB('bind9', '192.168.192.2' , 5432, None, None, 'named', None)
dir(db)

['_DB__args', '_DB__attnames' , '_DB__pkeys', '__doc__', '__init__', '__module__', '_do_debug', 'clear', 'close', 'db', 'debug', 'delete', 'endcopy', 'fileno', 'get', 'get_attnames', 'get_databases' , 'get_tables', 'getline', 'getlo', 'getnotify', 'insert', 'inserttable', 'locreate', 'loimport', 'pkey', 'putline', 'query', 'reopen', 'reset', 'source', 'transaction', 'update']

so theres no cursor i could try like your code does ...
thanks for your response ...

In my code.

Jul 18 '05 #3
gry
import pg
db = pg.DB('bind9', '192.168.192.2' , 5432, None, None, 'named', None)
db.query('creat e temp table fffz(i int,t text)')
db.query('copy fffz from stdin')
db.putline("3\t 'the'")
db.putline("4\t 'rain'")
db.endcopy()
db.query('commi t')

Note that multiple columns must be separated by tabs ('\t') (unless you
specify "copy mytable with delimiter ...").

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1689
by: news.paradise.net.nz | last post by:
My database appears to be a little corrupted, so far it's running along 99% ok, but i am getting some strange results. Primarily i can't back it up because of the following error. Similar errors occur when I try to drop a table. boo:/var/backups# su postgres pg_dump rj > /var/backups/rj.dump pg_dump: FATAL 2: open of /var/lib/postgres/data/pg_clog/0004 failed: No such file or directory pg_dump: lost synchronization with server,...
3
4195
by: N.K. | last post by:
Hi, I've just installed postgres on the Linux server. It is supposed to start automatically which I think it does since I can run an sql stmt right away. When I'm trying to connect from a remote machine I get a message that the remote machine IP address is not specified in pg_hba.conf, that there is no record of that machine there. ph_hba.conf is set up correctly, because when I run the following: postmaster -i -D /var/lib/pgsql/data...
4
8516
by: Bernardo Robelo | last post by:
Hi, I am interested in migrating Microsoft Access database to Postgres database. But I do not have idea of like initiating. Maybe some tool exists for this problem. Thanks you. Bernardo
6
2949
by: Prabu Subroto | last post by:
Dear my friends... Usually I use MySQL. Now I have to migrate my database from MySQL to Postgres. I have created a database successfully with "creatdb" and a user account successfully. But I can not access the postgres with pgaccess.
3
1809
by: Darkcamel | last post by:
Hello all, I am new to postgres and don't really understand how the database is set-up. I am very fluent with mysql and sql2000, but postgres is new to me. If anyone can point me to some good links I would appreciate it very much. Thanks, Darkcamel
18
5138
by: Joe Lester | last post by:
This thread was renamed. It used to be: "shared_buffers Question". The old thread kind of died out. I'm hoping to get some more direction by rephrasing the problem, along with some extra observations I've recently made. The core of the problem is that Postgres is filling up my hard drive with swap files at the rate of around 3 to 7 GB per week (that's Gigabytes not Megabytes) . At this rate it takes roughly two months to fill up my 40...
4
12510
by: Goutam Paruchuri | last post by:
Iam trying to import data from ms-sql server to postgres. I export the data which has datetime columns in sql server using BCP. I use the following to import back into postgres. copy tablename from 'c:\\bcpdata\\mcfa\\tablename.txt' with delimiter as '\t' I get the following error !! invalid input syntax for type timestamp: ""
5
5906
by: damacy | last post by:
hello, everyone. i am trying to write a program which executes SQL commands stored in ..sql files. i wrote a function called psql() whose contents look like the following. .... os.popen(command)
2
7332
by: clearissues | last post by:
Hi All, I have a python script which takes dump of postgres and restores the same. When i take a dump there is no problem. command to take dump: pg_dump -b -c -C --format=c -d -h <<hostname>> -p 5432 -U postuser -f /tmp/april_23/abc.sql abc Restore command: pg_restore -c --format=c -h <<hostname>> -p 5432 -U postuser -d sfdb /tmp/april_23/abc.sql
0
8691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9038
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8920
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6536
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3060
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2351
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.