473,748 Members | 3,697 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 2945
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
1695
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
4205
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
8519
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
2954
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
1811
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
5152
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
12513
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
5913
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
7336
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
8989
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
8828
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9537
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
9367
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...
0
8241
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6795
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
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3309
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

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.