<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forum PostgreSQL - Usuwanie kolumn z widoku]]></title>
	<link rel="self" href="http://forum.postgresql.org.pl/extern.php?action=feed&amp;tid=1855&amp;type=atom"/>
	<updated>2013-06-17T18:56:25Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.postgresql.org.pl/viewtopic.php?id=1855</id>
		<entry>
			<title type="html"><![CDATA[Odp: Usuwanie kolumn z widoku]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=4593#p4593"/>
			<content type="html"><![CDATA[W [url=http://www.postgresql.org/docs/current/static/sql-createview.html]dokumentacji[/url] piszą, że istniejące kolumny wraz z ich kolejnością są stałe (mimo użycia magicznego OR REPLACE):

[quote]The new query must generate the same columns that were generated by the existing view query (that is, the same column names in the same order and with the same data types), but it may add additional columns to the end of the list.[/quote]

Moim zdaniem ten OR REPLACE to nie do końca dobrze przemyślane/zaimplementowane rozszerzenie SQL, stąd to zamieszanie co do oczekiwanej funkcjonalności. W dodatku jest to konstrukcja nieprzenośna na inne silniki bazodanowe, stąd jako dobrą praktykę radziłbym unikać jej stosowania.

Swoją drogą znalazłem dyskusję na ten temat wśród developerów Postgresa. m.in. Tom Lane [url=http://postgresql.1045698.n5.nabble.com/patch-Add-columns-via-CREATE-OR-REPLACE-VIEW-td1996186.html#a1996192]wypowiada się[/url], że pierwotnie planowali tutaj większą elastyczność włącznie z możliwością usuwania kolumn z widoku, które nie są dalej referowane (tak jak w twoim przypadku). W każdym bądź razie mieli dobre intencje, ale średnio to wyszło.]]></content>
			<author>
				<name><![CDATA[gszpetkowski]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1223</uri>
			</author>
			<updated>2013-06-17T18:56:25Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=4593#p4593</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Usuwanie kolumn z widoku]]></title>
			<link rel="alternate" href="https://forum.postgresql.org.pl/viewtopic.php?pid=4590#p4590"/>
			<content type="html"><![CDATA[[code]create table A (a1 int, a2 int, a3 int);

create or replace view V as 
    select a1, a2, a3 from A;

create or replace view W as 
    select a1 from V;[/code]

Teraz jak chcę:

[code]create or replace view V as 
    select a1 from A;[/code]

To dostaję:
[quote]BŁĄD:  nie można skasować kolumn z widoku[/quote]

Oczywiście mógłbym usunąć widok V i stworzyć go od nowa, ale wtedy muszę usuwać też widok W.

Można sobie jakoś z tym poradzić ?]]></content>
			<author>
				<name><![CDATA[tomek]]></name>
				<uri>https://forum.postgresql.org.pl/profile.php?id=1459</uri>
			</author>
			<updated>2013-06-17T13:55:27Z</updated>
			<id>https://forum.postgresql.org.pl/viewtopic.php?pid=4590#p4590</id>
		</entry>
</feed>
