Re: Solving the SQL composition problem

From: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
Cc: "psycopg(at)postgresql(dot)org" <psycopg(at)postgresql(dot)org>
Subject: Re: Solving the SQL composition problem
Date: 2017-01-04 00:03:35
Message-ID: b1f5e3eb-76e4-9ec1-e25d-90767dcfa0fb@BlueTreble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On 1/3/17 10:35 AM, Adrian Klaver wrote:
>> What I'm suggesting is to let Postgres handle the replacement of normal
>> values, using the prepared statement syntax of $1, $2, etc[1], and only
>> do identifier replacement in python (using quote_ident). That means a
>> lot less time spent parsing, and opens the door for eventually doing
>> more efficient stuff over the wire, like using binary type formats.
>
> I believe a path to the above is explained here:
>
> https://www.postgresql.org/message-id/AANLkTi=ym3SCQKCQBtp8RJHUswwAPOpjXYKTXS=aHWzp@mail.gmail.com

Seems reasonable at first glance.

Speaking of type compatibility and what-not... I find it irritating that
we need to maintain that in two different places (psycopg2 and
plpython). It'd be damn nice if we could abstract that out somehow, as
well as fixing plpython's brain-dead behavior with nested types (arrays
of complex, or complex with arrays or more complex types).

I've also been mucking around with having the SPI functions in plpython
return something that looks more like a dataframe. I've got working code
but have yet to figure out a good interface. Part of that is trying to
figure out how to deal with a bunch of different possible arguments in
the C code. I'm thinking the most flexible API would be something like

plpy.execute(..., container=[], members={})

to match existing behavior. You could then do container={}, members=[]
to get something that looks like a dataframe. Or (theoretically) you
could pass in the desired Pandas types (I think that'd be
contairner=pd.DataFrame, members=pd.Series).
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com
855-TREBLE2 (855-873-2532)

In response to

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2017-01-04 14:37:46 Releasing Linux binary packages of psycopg
Previous Message Daniele Varrazzo 2017-01-03 16:40:57 Re: Solving the SQL composition problem