COPY view

Started by Karel Zakalmost 21 years ago11 messagespatches
Jump to latest
#1Karel Zak
zakkr@zf.jcu.cz

Hi,

attached is a patch that implements "COPY view TO" feature.

Karel

Example:

test=# CREATE VIEW vvv AS SELECT a.id, a.data AS d1, b.data AS d2 FROM
tab a, tab2 b WHERE a.id=b.fk;
CREATE VIEW
test=# COPY vvv TO '/tmp/test';
COPY
test=# \! cat /tmp/test
1 aaa AAA
2 bbb BBB
3 ccc CCC
4 ddd DDD

--
Karel Zak <zakkr@zf.jcu.cz>

Attachments:

pgsql-copyview-29092005.patch.gzapplication/x-gzip; name=pgsql-copyview-29092005.patch.gzDownload
#2Bruce Momjian
bruce@momjian.us
In reply to: Karel Zak (#1)
Re: COPY view

This has been saved for the 8.2 release:

http://momjian.postgresql.org/cgi-bin/pgpatches_hold

---------------------------------------------------------------------------

Karel Zak wrote:

Hi,

attached is a patch that implements "COPY view TO" feature.

Karel

Example:

test=# CREATE VIEW vvv AS SELECT a.id, a.data AS d1, b.data AS d2 FROM
tab a, tab2 b WHERE a.id=b.fk;
CREATE VIEW
test=# COPY vvv TO '/tmp/test';
COPY
test=# \! cat /tmp/test
1 aaa AAA
2 bbb BBB
3 ccc CCC
4 ddd DDD

--
Karel Zak <zakkr@zf.jcu.cz>

[ Attachment, skipping... ]

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#3Bruce Momjian
bruce@momjian.us
In reply to: Karel Zak (#1)
Re: COPY view

This patch implements the COPY VIEW TODO item. Do we want to apply it
for 8.2?

---------------------------------------------------------------------------

Karel Zak wrote:

Hi,

attached is a patch that implements "COPY view TO" feature.

Karel

Example:

test=# CREATE VIEW vvv AS SELECT a.id, a.data AS d1, b.data AS d2 FROM
tab a, tab2 b WHERE a.id=b.fk;
CREATE VIEW
test=# COPY vvv TO '/tmp/test';
COPY
test=# \! cat /tmp/test
1 aaa AAA
2 bbb BBB
3 ccc CCC
4 ddd DDD

--
Karel Zak <zakkr@zf.jcu.cz>

[ Attachment, skipping... ]

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

--
Bruce Momjian http://candle.pha.pa.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

#4Andrew Dunstan
andrew@dunslane.net
In reply to: Bruce Momjian (#3)
Re: COPY view

Bruce Momjian wrote:

This patch implements the COPY VIEW TODO item. Do we want to apply it
for 8.2?

I thought the consensus was that it would be better to do

COPY (SELECT ...) TO ...

rather than requiring the intermediate creation of a view.

cheers

andrew

#5Bruce Momjian
bruce@momjian.us
In reply to: Andrew Dunstan (#4)
Re: COPY view

Andrew Dunstan wrote:

Bruce Momjian wrote:

This patch implements the COPY VIEW TODO item. Do we want to apply it
for 8.2?

I thought the consensus was that it would be better to do

COPY (SELECT ...) TO ...

rather than requiring the intermediate creation of a view.

Right, but even when we have that, should we be able to dump a view just
like a real table?

--
Bruce Momjian http://candle.pha.pa.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

#6Andrew Dunstan
andrew@dunslane.net
In reply to: Bruce Momjian (#5)
Re: COPY view

Bruce Momjian wrote:

Andrew Dunstan wrote:

Bruce Momjian wrote:

This patch implements the COPY VIEW TODO item. Do we want to apply it
for 8.2?

I thought the consensus was that it would be better to do

COPY (SELECT ...) TO ...

rather than requiring the intermediate creation of a view.

Right, but even when we have that, should we be able to dump a view just
like a real table?

Wouldn't it just be this? :

COPY (SELECT * from viewname) TO ...

I don't see why views should be special. Tables clearly should be
because we can open them directly.

cheers

andrew

#7Bruce Momjian
bruce@momjian.us
In reply to: Andrew Dunstan (#6)
Re: COPY view

Andrew Dunstan wrote:

Right, but even when we have that, should we be able to dump a view just
like a real table?

Wouldn't it just be this? :

COPY (SELECT * from viewname) TO ...

I don't see why views should be special. Tables clearly should be
because we can open them directly.

Ah, I didn't think of that. Good idea. So we don't need this patch?

--
Bruce Momjian http://candle.pha.pa.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

#8Andrew Dunstan
andrew@dunslane.net
In reply to: Bruce Momjian (#3)
Re: COPY view

Hans-Juergen Schoenig wrote:

we agreed on the view solution as people thought that this would be
better and less intrusive. I was also in favour of the syntax your
described below but people voted for the view solution which has been
fully implemented by this patch.
Btw, it seems to be stable - it has been in production at a customer
for quite a while now.

See this recent thread:

http://archives.postgresql.org/pgsql-hackers/2006-06/msg00055.php

cheers

andrew

#9Andrew Dunstan
andrew@dunslane.net
In reply to: Bruce Momjian (#7)
Re: COPY view

Hans-Juergen Schoenig wrote:

why do we agree on a patch, implement it and reject it then?
would be easier to reject it before actually implementing it ...
it is quite hard to explain to a customer that something is rejected
after approval - even if things are written properly ...

That's a good point and I understand the pain.

Could we maybe do this?: Take the patch as it is now, and if/when we
get the more general syntax we do a little magic under the hood to turn
COPY viewname TO
into
COPY (select * from viewname) TO

just a thought

cheers

andrew

#10Bruce Momjian
bruce@momjian.us
In reply to: Andrew Dunstan (#9)
Re: COPY view

Andrew Dunstan wrote:

Hans-Juergen Schoenig wrote:

why do we agree on a patch, implement it and reject it then?
would be easier to reject it before actually implementing it ...
it is quite hard to explain to a customer that something is rejected
after approval - even if things are written properly ...

That's a good point and I understand the pain.

Could we maybe do this?: Take the patch as it is now, and if/when we
get the more general syntax we do a little magic under the hood to turn
COPY viewname TO
into
COPY (select * from viewname) TO

We could. But we would do it because we want that behavior on its own,
rather than doing it just to support a feature we added in the past.

The question is, if we were adding the query syntax _now_, would we want
to do views that way? If so, we can add the patch and just fix it up
when we get the queries.

--
Bruce Momjian http://candle.pha.pa.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

#11Bruce Momjian
bruce@momjian.us
In reply to: Karel Zak (#1)
Re: COPY view

Your patch has been added to the PostgreSQL unapplied patches list at:

http://momjian.postgresql.org/cgi-bin/pgpatches

It will be applied as soon as one of the PostgreSQL committers reviews
and approves it.

---------------------------------------------------------------------------

Karel Zak wrote:

Hi,

attached is a patch that implements "COPY view TO" feature.

Karel

Example:

test=# CREATE VIEW vvv AS SELECT a.id, a.data AS d1, b.data AS d2 FROM
tab a, tab2 b WHERE a.id=b.fk;
CREATE VIEW
test=# COPY vvv TO '/tmp/test';
COPY
test=# \! cat /tmp/test
1 aaa AAA
2 bbb BBB
3 ccc CCC
4 ddd DDD

--
Karel Zak <zakkr@zf.jcu.cz>

[ Attachment, skipping... ]

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

--
Bruce Momjian bruce@momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +