473,378 Members | 1,330 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

PyPGSQL - OID

Der Python DB API supports the method oidValue on a cursor instance.
On PostgreSQL I get the internal used oid from each row, but I need
the id from the primary key. Is there a way?

Thanks
Jul 18 '05 #1
1 1616
Manuel Huesser <sy********@gmx.net> writes:
Der Python DB API supports the method oidValue on a cursor instance.
On PostgreSQL I get the internal used oid from each row, but I need
the id from the primary key. Is there a way?


If you're setting the primary key from a sequence then you can
use CURRVAL('sequence_name'). For example, suppose you have
this table:

CREATE TABLE person (
id SERIAL PRIMARY KEY,
name VARCHAR(64) NOT NULL
);

PostgreSQL will create a sequence named person_id_seq that will
be used to populate the id field (the primary key). After an
INSERT, you can use CURRVAL('person_id_seq') to refer to the
primary key:

curs.execute("INSERT INTO person (name) VALUES (%s)", ["Guido"])
curs.execute("SELECT * FROM person WHERE id = CURRVAL('person_id_seq')")
print curs.fetchone()

CURRVAL() returns the most recently used sequence number in the
current connection, so you don't need to worry about the value
being incremented by other connections before you get a chance
to query it.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
Jul 18 '05 #2

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

Similar topics

3
by: Paolo Alexis Falcone | last post by:
Whenever I try to access a table with many rows using PgSQL's fetchall(), this happens: >>> from pyPgSQL import PgSQL >>> db = PgSQL.connect("192.168.0.8:5432:whitegold","dondon","dondon") >>>...
0
by: Timo Virkkala | last post by:
Hello. I'm having some trouble with getting the pyPgSQL module to work. I installed it and the mxDateTime module into my local directory (I'm doing this on my university's server and I don't...
2
by: Rene Pijlman | last post by:
I can't seem to find any way to specify the character encoding with the DB API implementation of PyPgSQL. There is no mention of encoding and Unicode in the DB API v2.0 spec and the PyPgSQL README....
0
by: John fabiani | last post by:
Hi, Does anyone have this module running on SUSE 9.1 python64???? John
2
by: Frank Millman | last post by:
Hi all Below is the text of a message I was about to send in connection with an obscure problem. I have now almost got to the bottom of it, and am fairly confident that it is a bug in pyPgSQL. I...
2
by: J Dubal | last post by:
Hello good people, Following works in FC1 (python-2.2.3-7, postgresql-7.3.4-11, kernel-2.4.22-1.2194.nptl, pyPgSQL-2.4) from pyPgSQL import PgSQL conn =...
3
by: Gurpreet Sachdeva | last post by:
I am using Redhat 9.0/python2.3. I installed pyPgSQL-2.4.tar.gz and it was successfull. Now when I am trying to import that module, I got: Python 2.3.3 (#1, Jan 11 2005, 15:24:09) on linux2...
9
by: Tin Gherdanarra | last post by:
Hallo, I'm trying to install pypgsql. However, I get syntax errors while compiling the C sources. The following excerpt from pgconnection.h looks a little funny to me: typedef struct {...
0
by: Eric | last post by:
Hey guys, Has anyone seen this error when installing trac? The problem seems related to pyPgSQL, which is installed. (Although I had to go in and add some headers to make it work) Templates...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.