English 中文(简体)
心理范围2 + 储存程序+化合物类型
原标题:psycopg2 + stored procedure + compound type

我的存储程序载于PogreSQL, 采用t_document。 定义如下的复合类型:

CREATE TYPE t_document AS (
    title    text,
    metadata text,
    data     text
);

储存程序还涉及其他论点,其签署如:

CREATE or REPLACE  FUNCTION sp_insertItem
(
    name varchar(100) ,
    phone varchar(100) ,
    address varchar(150) ,
    document t_document 
) 

Calling this stored procedure from another stored procedure looks like this:

sp_insertItem( Name , Phone ,  Address , row( Title ,  Metadata ,  Data ));

我知道,我可以采用<代码>cursor.questproc,提出必要的论点。 然而,我不知道如何通过诸如<代码>t_document等复合论点。 因此,我如何从预想一种化合物的精神病院2那里传出一个储存的程序?

最佳回答

You can pass name, phone, and address in a tuple, eventually with an explicit cast to better disambiguate:

cur.execute("sp_insertItem(%s, %s, %s, %s::t_document)",
    [ Name ,  Phone ,  Address , ( Title ,  Metadata ,  Data )])

你们也可以使用一个名人:它采用同样的方式。

Document = namedtuple( Document ,  title metadata data )
问题回答

暂无回答




相关问题
摘录数据

我如何将Excel板的数据输入我的Django应用? I m将PosgreSQL数据库作为数据库。

Postgres dump of only parts of tables for a dev snapshot

On production our database is a few hundred gigabytes in size. For development and testing, we need to create snapshots of this database that are functionally equivalent, but which are only 10 or 20 ...

How to join attributes in sql select statement?

I want to join few attributes in select statement as one for example select id, (name + + surname + + age) as info from users this doesn t work, how to do it? I m using postgreSQL.

What text encoding to use?

I need to setup my PostgreSQL DB s text encoding to handle non-American English characters that you d find showing up in languages such as German, Spanish, and French. What character encoding should ...

SQL LIKE condition to check for integer?

I am using a set of SQL LIKE conditions to go through the alphabet and list all items beginning with the appropriate letter, e.g. to get all books where the title starts with the letter "A": SELECT * ...

热门标签