开发者

Postgresql: how do I manage a list of columns for use in SELECT ... AS and INSERT queries?

What is a more efficient and stable (defined only once) method of picking out a list of columns for use in INSERT and SELECT statements? Specifically, I have a query like this:

INSERT INTO "mytable"("column") VALUES
('col1'),
('col2'),
('col3'),
...

And also a query like this:

SELECT * FROM myfunc(args)
) AS (
"col1" text,
"col2" text,
"col3' text,
...

with the point being that I would like to define "col1", "col2", etc. elsewhere, somehow (function? table? combination?) only once, and use that list of columns in my queries. This way, I define the columns 开发者_如何学JAVAin one place only, and, I shorten the queries. It'd be fine to somehow use mytable in the SELECT query.

Thanks


Try Composite Types: http://www.postgresql.org/docs/8.1/static/rowtypes.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜