Temporary tables patch and postgresql's COPY

66 views
Skip to first unread message

vomjom

unread,
Jun 13, 2008, 11:28:37 AM6/13/08
to sqlalchemy
I submitted a temporary tables patch that basically allows you to put
a prefixes keyword when you create the Table():
db = create_engine('sqlite:///')
meta = MetaData()
conn = db.connect()
meta.bind = conn
tbl = Table('foo', meta, Column('bar', Integer),
prefixes=['TEMPORARY'])
meta.create_all()

http://www.sqlalchemy.org/trac/ticket/1075

I hope you'll accept the patch, considering that was how it was
discussed in the mailing list a month ago.

I'm wondering though. Will you accept an enhancement that allows you
to use postgresql's COPY in a similar way to how psycopg2 implements
it?

In psycopg2, there are three functions: copy_from, copy_to,
copy_expert
curs.copy_from(io, 'test_copy') will initiate a COPY using io (which
can be any python file-like object) to the table 'test_copy'
copy_to is similar and copy_expert allows you to form your own COPY
statement.

With postgresql, COPY is far faster than doing inserts.

Thanks,
Jonathan Hseu

Michael Bayer

unread,
Jun 13, 2008, 11:37:07 AM6/13/08
to sqlal...@googlegroups.com

On Jun 13, 2008, at 11:28 AM, vomjom wrote:

>
> I'm wondering though. Will you accept an enhancement that allows you
> to use postgresql's COPY in a similar way to how psycopg2 implements
> it?
>
> In psycopg2, there are three functions: copy_from, copy_to,
> copy_expert
> curs.copy_from(io, 'test_copy') will initiate a COPY using io (which
> can be any python file-like object) to the table 'test_copy'
> copy_to is similar and copy_expert allows you to form your own COPY
> statement.
>
> With postgresql, COPY is far faster than doing inserts.

theres nothing preventing you from calling copy() from the cursor
yourself .....

conn = engine.connect()
cursor = conn.connection.cursor()

# go nuts with cursor

as far as a "COPY" SQL construct, these are welcome as patches (which
include unit tests) to be added to the postgres dialect, i.e.

from sqlalchemy.databases.postgres import copy_from

engine.execute(copy_from(sometable, 'somestring'))

Reply all
Reply to author
Forward
0 new messages