Hirarchical queries a la Oracle. Patch.

Started by Evgen Potemkinabout 23 years ago5 messages
#1Evgen Potemkin
evgent@ns.terminal.ru

Hi there!

Patch is posted to pgsql-patches. docs inside.
SQL 99 version will be later.

regards,

---
.evgen

#2Hannu Krosing
hannu@tm.ee
In reply to: Evgen Potemkin (#1)
2 attachment(s)
Re: Hirarchical queries a la Oracle. Patch.

Evgen Potemkin kirjutas R, 22.11.2002 kell 15:57:

Hi there!

Patch is posted to pgsql-patches. docs inside.

It would of course be nice to support both Oracle and ISO/ANSI syntaxes,
but I'm afraid that the (+) may clash with our overloadable operators
feature.

SQL 99 version will be later.

I attach a railroad diagram of SQL99 "WITH RECURSIVE" and a diff against
mid-summer gram.y which implements half of SQL99 _syntax_ (just the WITH
{RECURSIVE} part, SEARCH (tree search order order) and CYCLE (recursion
control) clauses are missing).

WITH clause seems to be quite useful in its own right as well, not just
for recursive queries, so I guess that someone with good knwledge of
postgresql internals could get plain WITH working quite fast -

The main difference between subqueries defined in WITH clause and in
FROM clause is that while subqueries in FROM don't see each other in
their namespaces, the ones in WITH either see all preceeding ones (plain
with) or just all in WITH clause (WITH RECURSIVE)

--------------
Hannu

Attachments:

with_clause.gifimage/gif; name=with_clause.gifDownload
GIF87a�%�beb������������������101������RUR���   susADA���������������������������������������������,�%� �di�h��l��p,�tm�x��|����pH,���r)1���tJ�Z���v��z�)'xL.����z�n���{N�����~�'�����������I���������L�$������������������������������������������#�#��������g��������������.*#�������I�r�+#�	&
		
�sG������3�M�I88P����	3j���#��%<H�`���4������@A	�GB�2�����M�H�*]���K�sP����/!*� ����
�8��M+<l�����I�@��3�B��q�����z@].�*^���5��0@���z��`P���ugV�@�s�S�^��dh�YB�+U����J/*�r���k@������+_N����6@r���W@�����;0��A��1��������O���������>��(��
h��&�8C�
6���2��V���f���ma��� �h��"�h�������,����.�(��v�H��8���:����OC@�Fv($CI6���9��!Ii�$P^��^���)��d�i��h����l����p�)��t�i��x�	�ny�����*���jh�^v��w����	):
��
^5);�i6�-J�%!Z������
�&�[����j-�z�H����*]:�\���k���&����.�Q
��2��B����@@��v�����K��)���w!�(���������������4D���l(p�?\���l��'������
A+%W�n?����w��� �,2������@��n,��0�<0�K$��8�\0�7L����2���--`�>Gb�B=Z����0�#w� z�v��MOz5Y�ve��k4C���i �gA���@�{�uz[=[#i���Z�d��c�8	��48N*�L�Q�\�����@�
����x"�����$��R��F�E4��1p�7}w
��0�}G���=�N�HU���~Gn��D@�����;�3�q��@����B�������{��&D��?6�����`PT�
�U�5BK�0�?���\1�����L����{���	��8��k�@p�1�u,��	>w�A�Z�c�s���@07��?�
��|A_
lx���p%<�[�>�� �W��� W�hS����+���_�B�8������&!��!@z# @mJ�B�p���c0G����	
��2���8�K-�E�:���'���\A)W%<@�`YDH�DZ��&T�
	8���/`�a�H���������F�D�x�\	�U�#/,��Oj�nM
x��hR�\%;!���/q3&����L��$�	��h�B']2�P��Nh�#�1/UI���%J�lg4{2Ltr�(�W$u������y�1OqD����WtR~������8e0I����
�,3��`!I\��(
���rrAM�$�v�%�"A������M2���<
�'�I2�R������JV�����s��$i��+���Jo3�4`�(��@�A�5-���p^�&R
�g�:=�z��\��F���D��5�
P��$���@�J����'P+
:��9�Q:}�y�JO��/-m��*f��p-��H9�C�T
���n@��V�%�o������X�aW�j�����`�`���1+Kk�:�07o��x�����-�����f�����_�\�����,q
P^lQ>���Dp����{m���`���.k�6��!��"A{���������g�R�>
H.F9�Vt�aH���Ct'�$�R�S@��4�	X��Q���,Nh�K����IelLV���@%�����H���8����V�q(_����)Y���al���-7�����u��UQo\Q�C�����x�i��@��\h����pg�R;*��#��21B�s�M7,Q�9�����"8.F�H.N���((��
Q�A��'��K,���.�"Hb�/��4����N>�&�80v+m(�bg7 �d�s�Qt��E���w���T��������n��z0�N���SnhgvW��@���v��X9NEs���Yv��}��<��EA�]������{<KD[����:?1�_������4�N�����g���@���"��o�An�0��}'u���$��'~�]u�v��0�$z8r��L�+�)�����1&[zE��E�I������D��8:���=�$u	�����lgz$7���~�����|��U�_��>���?���:��Iw�c���Qv�W����k���,�x%������_��`�[YS�C������B@n�%��	�����u�D��l�K��s����������
��R������-�Kp�;�������w;�<�Q������� ��	\���Q��a���~h�<x�7���#ql�q��5�S=�=-�X."h,@fp>%��>1��z!(I�z0pI�v0�2��2{�Cq6�gu��A
�03�B8�D8?��v)�9��e_7N��sV�F�c~*0a1��!�2�)@0YR2EX�fx�h����z0,�pGac����6hT-@�dp>Xx�+h}/%xr.)c�5�g�?j�	`�*(��2��,��&?�/���!�/�74�G��;-a{&��b�Cq2�bD�f�c� j. 7�%�K��l���q�c��b������X|�sy�}Up�����Is�0������/a��K hA���&���2�W�7�X|�*��6*��|@;��-o������1�����7�x[���#7�Xy����(�����|����X+F�oP3�=�bX��3���`/�-��z�h�=?G37��=��&sRs2�2	.�Wf2vt��!T�4�[�z�5�a4y�#��AAI���3���4	��^�V�,5�YL�3��/��<�;.;tg:s�#f2���/���\P�.�l�C �����z��0�9�-=���T�)�K�r!��8w�3N�B��t�z|Y�1�8����g���0���u�#�1�@���
��b�d �-@A��|W���<���)0Z�K?9��9�9=~�G	��g�p�e�v'�#�yK�6C��!7p1(B��4UY��P�.7I��2�A��F�~� ��~�@�1|H�I~�X�_��@)p����VN��1�����8�.`#QAc�-�D��F^qyU���gD-�9�i�H:GYf�w��)j�M��c���;Y�Uo��c�)a�P�G��G{���������	D�H�����G�d' 7��Z�R:�5�K�$��R��o�5'aQiP�t:��Pc�L�N�4MQMe��&Fce���7��FdV�gJ,C,eE�kk4K�$����Ng��>1H�j��DgzE��N����s���6J7�Sj���������L�@���}#)�*2T�9 ��|�UE0^�3�_�%�-&q�����	���v��V�@UT$WY�T�Y&�Jcxg��W�B�47I�_NZy2%:6W\��FiWV����\�E��J��S�i�@���VnV��TQ���0�k9�FGA��p�=4���w�����#\�ba		�Q\

\��ua05x��2;(��b�;i�%qW��h�2G`^]��`F����'b��3��N��9&dB���^r�ZO�8c�-�
^�&�����`��BJ��j��D�^`gU��`T�\1g6&�^���L�~+'_R&!UP[�hB0�v&�#;i��j)��s�bO�E�U�����c��F���zh�I�Hjv��;B���"��`W(���Vy���%�C�d��\��Z����( ��EE��h�VY�d���*��[�fe����cH"{2�'@C(A<�u,[��������b\��p��9&���/���pG����k�� �k�H&E$sj�c�R�,��)E+���E�aoz%p_�i]U���6�+�{`SR��e�%��f(�3��
�����P��sV��r��j$8��x*e�q`��J�g�x�DVW=��y[uA�y��q�) �3W�v2Vsa�r��3/��N�\ULT)V��F<r�M5gT]s4�2+c�Pl:"Pwb*��i�jv:B�1S�U\��#���T� ��B��"��@@Z�{�/�F���5������J�@c@�+7�#��������D0�&������s���.��{+��G�t������o����<�.�F`�o��9y�1!�7P�(r���c�f�Ln����~����}���������$:UO��n�I�fw"�C�1P1��v���S��BP:���4�4�(���i����K���B=�e����2OCO���z;���I#�6�*#!�m.�p�����U��7��'R14���]2��%��X���m�.>=7'
�\Y���j�'���l[�ex�(Z=�;-��R���(�p�r��������l����Y�'y���]@��d��2��
�ui[z���������P��}����������������=��]�@#�����!
��������=����}���������q����M�=��}��P���������������]��CR�������������=��]��p�{�����������,8�]��=7(��-�G��M�[y7	A��+���M,�HS���I��\�6�
P�AQ�O
UO�'�U�O%L�N�$�(>#�mXp�}e����*�m��.�U���>."+�m�`�`Td`NtZ�E]�q_o��Pn"A�m�h9�hLEh������a�e�b�S�CRmo��a��$��p��p�p|n�<�x�e~m�xw�y��w����y%UG�7���^���N!{n�����=������<�UP������T��~��B�S`����N��R���>�@�Q ����9b�P�����2��O���^�+"�L@����@��^����"�����^!���~��� ������~ ���>�� �~���K�]�����n�>���b��@��,P�Ep���1��%���6e �	o!���9w.�O����+ ��/����g%9����o����nT�_�C��*�
��h���0��=�H��/o������A �<�
z�{)��DFO����R?�3��l��T��Z�'SS4o��?����<-"V~^m!m(�	�> ��
�%���Gio!��n�p��w�!Y�DX�a� G�{�}���� �F��H����4�=�+��*��<�M��;���}�(�*@��%�#R��/�an -q��"��
�����? :�7'��jO�f�����B���+/��-b��p�8@����T��."�������o �y#���o�o���O����p�5��0������O�����O	  #Y�'��+�"�3]�7��;����'��#2�\2���3*���;W�j�r���

���3:V���6	Kz���{R���������D��!��������d�%��c&g�gWD�(���)j�)��h���g�d[e@���.�,�/p0K���`�Ac��0Y��m�s�5�����@����CB3w5�4z�{�{�<XC��C�����3����� ��C
0�Ec���'
�1��.
	hf ���6�,i2M�Z0��^6(��\��I<�����@�&�z�s����n�hE(Q<��������"
$�z�A�#��:"�qG<p�S,��c��������0Ha��Q�
��{��f�)�����2��3s�� T
,*
x`���p�f����`.��-c���hJ?@z��Q���,
	6z��~e���z	���oQ�6@=�-:��`��J�d�@����������u���_�T��e@@��J0S4�	����_X�u���q"�B4]��V��G��\�X"f#�xc�@��?�v��B��U�[���_C"�$�'�w`���1��h�L����]� YS�P�*����!i��^f���^�R�2?�`
C����S�'P{��3��R�
4 �+�F��'�)������4fS9�$��!&Ac6�y��f:�����(	5�
�� ���jb���b�a�+l��%��7i�[���r&�	��`��:����H��W�����m��*n�DnB�6�-����%�8
-�A�p�\k��j������%�+���A��1\��L�[�6oS�j�1�{��
�z<2�%�|�I4��#lt���lX
��/Sl���P`pA=4�E-4{5�@�G;�4�Q
��HP*,< ��P��rvJ�x�����sI=J��U���#
w.2s���v�M�D�����F��
�X��p�f[��1�L����X�a�T�2�����H���/�#~��,��
�WO�K���[w��+0�-bf�-p�S-��>�a���$��7��`��a��
�9�il5 ����<feJ��)��9'\h`b��>�h�@��b���gB�+��#e�O0����T@3H�e1�����@L�)�|"2G]J;z^������#Ak�����"2��2"�o��Fy�
CS�1
r�������q��D����%rP�U`��`e%x�	����I����K�����=� C�?;����ss@L����S����*I�b
�"��\����"���C�c	�Re��: ��J(�\y���*i�i*��X��l�:����10P�M`uF���#`jL`I�����d�'=�����}��C�4��(P��H��\%��!Z���bTZA������,��c�`��[���]����"p������l�`Z��E-���"��|���A$�_n�D@���D�0��c^�%AJJ��hN5�\L��R����iM�(S25j9�h��F�Bd:ddOE�������r����$
�z��R
�%J��*��/Wj��h&IG�``��hM
��aF�Y!�)"w�����@��_K �[@2���ZS�������Ka>�K��'��y�#�!6@%C,ekj�x�'HlkrW�� 
�([EK�&�]����(5�u��f�K;�B�$QI�)`��l�(����i�����y$%�]�9�m
�p�H��5�l��{T����dm
Q�����&�Q��d��;��p�p���]�
�����Y4��C���bFa�����r(6��=:I �uk������oY�	��;�6�Li����<��PG����e�EZ����i�)	��8#@�dY::����HzK�M����#7j��6��7��*G
�Qo@ .���G�Z2S�U@�%�[I(����z]���%82���Q8�,<���ad��O��Y2V�����I��F]Zp(R9��I�Yj�����	E:��7�`�is=
�����P����M�QT��@���$�X���*`�Vd�wN�\�kl(�Ci
�0?��9Oj��w�>'�#���6w���j�U�_���'U�0,	�co�.�@q�`5�Q<F��U��(�G�J���8i;�2�j@�R�����p!���-=�b���A�"	`]�W4"L�� ~���FG�o.�r���	2����.���{8(@����L�e��' #��C�T�b&~�{���I���.�����Z)�^>�P���~G�j@���`a��2�����73�4��i���
�9
=������E5�x#/�m0
T��l:Z������>^��c��O��;�)��U��=��/�B� �>B��9�sc.����/���Z�������r��`s�z�����P��Bn���^g u�c�:�G���{}���z�C*tQ���,�d��V�aN�����
���7@=`�H�tA=���|��(�P�����m���@tN�q6����Z��
���*0�K���

��������n	��5�� +l��]��@Z��t<X������A���	zA
����JAm]����78��ya	hD��
��f|$a	��
`����"�a��P��� �GX��^b!��4�J��K*����[�t�0l���
\��A�!.��\��h�l�<��	�����i��=P�}�La�[�D�
��0��(�������.���]
\!	0F�K�C����y��DM����f�����
�`?u��p
D�#3�L�GD�?��J��2��8F�Y�}Cc�=��
���A��#���C�B��f#	�#7Fd!��l[d\-�������T#����]�U�G
�������IE�`
��#�4�"�
pY`����c�$,�\<���J:�T�1D���V'��-�C�V_���Z(nd��W���'X
�MnU��U��#��'�%�9�S�e
�Z�X#���>!1IR��!���z�����38D%���e:&f��2�X��S
 ���t�TQ	��U���?�;i2	|l�"���T�ap�mS�H�7��dx8JXbd��b�`�����,&&UW[<f��Y��O"�&��=tP�&}��P��i|S��������S}�:�?��f>�o�	D�0iWU����Y,�y,�e�����F���3��x
Sp����B���fL��7��]�)��X�Y��`�?d�P�0��Q�51U1aU�����,�}OMS3@��,��
!�0��w\v��x�����<���@�(hr0�G9(z���	[��K�G�j<RR5�=]�TUN�R���:�hL1b
��X���^�G|�,+t[
�
���������f�U�[����i�[,Gk��X��TQ���j��mL��Ehz��h��M}����W����gk������f	X|����D���H�v��~+����r+ox*�
Bo����k��V�n+�����j0��m)��nZc����iz���Fg�j��h5�	d`k���������R�D�%	�$[
���H�t&���zxlf��Wb�m���4�%�mW��"�n�E�)����G~��J�y>iM��J��p���z��JAD����V�\ZC�Fn��l��[�	P'i�yyz�����|��T��f��3������=N
�R��zW	����hZD�%�T@��b���/t�����]�����^�]�NWRa�M���8�`��5�e���EY��f��������I��=�c��X�z�����N�Rr�-�j���&���M��W.���.P
�d���������,P���Zgih���b��9@��\��m^�@��(��!��Z���������A��8}N���K�B�*���o�QZ��1�	��2D�E��-���et"���r�i��������)xd���I������D�Z ,���{Ap��@�E�X�0'�c��x��h�9�V�����xa��p����E����RaPp�91�iph=������4p���� 
������R�b,�(��V��
�e&��k����NWw��a�dA��Gj,����S+H����6"���?���
���������0�1�h2��?�.T�!�-��G4�562z���3DJ8���d{�rk	�
x�L���)���
��!������!(�� '�b���
�����A��/��8ps[}��)s�+��*/s����	&~�F�P�],�'z����a�����D���`J�����|�/P6�3v��;�lR�@�Am��T�\s����I���Y8�E�AC:I�����GK[6t�!����u��j�B�NO����!��R���X45�da�����
��@�����C7z =8n��$�RE����@g�#r�P�F��]�(����Ei5`^��4R
�d���EW��v`�^�����c�5�CP��jO�TW�d��[��^�f�]B-�Z6f+����P�N�Y6m����T���v��vm�vkW�!�30���g�p���d-�
.���T�3n_7v�d�����J���X�������H�&�F�������ug�|�w'l7t���\����j����*W_
S=��Q���/���
���(����?p�+X�J�l�#E28���/8�
@8�*j�g%��-Z������������JW��P=$�j������o��I%ZOS��o�f��G���A�����O>��9N9�w�T�\���H����9�C�U�&�#�9��������b{Am������S���6I������:�����[���m�K!P'��_z,z��6���1�
L�3����#2@#�<��$K���:�7,kz����C�	���:�����:���;���;�'��/;�7��?;�G��O;�W��_;�g��o;�w��;�����������y)����{��;��;�_���;��{������������{��;�<���<�'��/<�7��?<�G��O<�W��_<�g���;�w��<�����<�����<����w�H����<������*u4��|��<��[W�o�8������FW��)��/�����8x��GVA�M����ERUHf}9pM`=���u;}�2q�E����L
Q�f]H��jAi�������s���s��MqT���/��:��!��7~����z%��w!�hlT&%|�8�W�;��S��y�IDc�?�~[�.I_/�UN1Ye�n��������L�O���������	��P��*��>������K�K�$\��g���W�Ayk?��9�7�	(_��?����7������P����wy�/A��?�����D�����?�H��Y
������L��������
�����L*���S�|J������j�����E��1��N�����
��� ��������X�s7hx�������S�xIYiy����4y��	*:JZ��Y�j�����
�9K�@��������`�l|�������r����`0�B���������@��������[��?��r�o���b���+���������	� ���+Z��!-@�2���$K���@ 
><	�A��V<pp2���<KH�����0L�`�		z:}
�bJwG_F�j���L�z�
��d&�Vb�;M��XI�j=p�1��	�<1�R�w��Q�*M�
�t����@������;��s��@c��|b�[������g7�S���YJY�I�n�[Dn2@�Tm0h`�������F������(�����QXW�=BF��Z^~������m}c��!@�^�}8(0�R�G�{ht����9(BL�!�|r���"��Y$p�o���%*����0�9���?�h��2]r!�3�p�
)���$��D�4��N
�5���a�#����&�x�m�[�u@��C��IfDI��f�U�~b	N�l���-=�������|����Yk5�S�#�f4�-"0����P�#��	�T����_�_	���&`��F��`F��������`���K2���9��#ZS
Z��
56+�VK����Bm��l	���]��Nb�	(pW��6�_�2�?��+	��dP�Z�	�����,���$8p@�(
e��D���B�����=v,������	��0�ZR�a�����e�,Br8�����\��,[�~Zv�9 1��aoH��B�|e��`��0�s�I���!�I�a0����l��t9����\#���D�p��bw����w�4�������l�o%���F#-w
��d`�+�<�*�������TM
<�������u�~l����L5�	TFN?�`G/���0@��C�/��iv�������@M��l�����i���
|M	4p(�#P6@���]��~�/|�������@o��u���<$���`l�9���pG����w��_��������C�������x5�_��b�&P{G������LQ��	QD�v���IOp�\���
���C�'B���:&�_�F�B�p/��'E���pn8T��w��x+�������K<@9�<��4`vi�L�+�e/MU��X %&(�j��"=4�~��X�1	z��.���@�F}-\�������A��_
���6������L���Mfi�K f
�N���/a�Q*S]�9�V�'	�I��:�-g�g��%l�� �7�S�9�B����\(�\f�|	��(���1S���j��`��	,���;��e+�����s��\�0�c�C�S��l�%:�d4|���9yx����p�T�<�N�%���3�L4U!3�Y0w:M[�R���hi&*����#p�FA��Az��s�0�h�]zkP���J�j�(`�\7`+1A�f�k,�WV�#������R3��j?�Y>�5�\��'�	��93%%�Du���U�?����(�\6|��!B��<6��7$ *�C���g�j�
&c6���49c�b1
���4n���c�C�`h��Lm:*������X�����*t��Y��v���-�~�:��u�e,?'^�b������iO��������%��Y�M�i�Z��t��%n	�������|��������e)�\�jr�����;��.�@�	t+{�7}���en	�b�.W�q�n8rXDL�bX%�Y��2��Q�	�+��$�-�E���<��J��z-\Z�Nkn���Tr���*l��el��/MA��K��������M��0�V�l�j�r�����b�������H��i����h��kt>����`=�����e�*&
&�>~fh�j��@��DM����;X �a�d�B���t�*m�O�Q�$����(�F�i�Ml�J�i�xr�����Q)�s�4���gGf�-�1aS��"t���$��VG��\�2]���r6���anr�~/5|��FjS�l#�cj�'���e�Y��S
�%h��������w�:5�KO����#dA���X��Q(�7U9B��������Vs�����OK�,,wJ~���*�s+x!v���-��9�$Fu�����&�|'�NO���-&�T}������ ���(8wq���3�#�4\����W�����W�H�|%��}��������kz4C�mm����A��w�������{�w�x����"P�!B�����kw0�f�1�@
�Ly�`���Y�Hi�����g�S���������5$����I����%7�+�T�j��K?�r���k��HGI��|���9F��m���E���T���C�
�!�"��!�3?��|�W�B}��E��}o"���G+�7:���r12qgb|�g��|�W|��|I��`sX����	�1!93��g}����#��(p�J0)��(�$�"=���
�v���T��q�^&�@kU}�w
��D������I�������4�C6����7�|��cxn��q&�H�C�'�NP/��-q�|��~0����`~������^X�=(5��}��Z�B�z���Pr~�cD���a@�"�t[���@k�dc��.��}���C��xF��{�P�5�($��3
�%s���x������@`'0��a$7�#������%���8�7�jp���!�q~I@�(�Xa����
R�SqS�X�!�> AD7�mcm����+/�c�u5����Hy)PFP�}�-_H����i{���
��Q8"�3�����U�S�������VY������n�d��!k�2i!&08��#�7��>�u�Q�4����������$���.�pC��1"[	o�Y
H�:p������H,	
�[1D�Y�,��p��91�������$�����aI#�y�W����l����hAAP��)$�i�]:K����������.���	��)��I��Y0p��� O-P/�	��)����j������I�����y���������i��������(ha����������r]�����ZJr$����	�*����.j�qB���
���)�����2j���������J�G��!*�#��2@���.'���I����/
�1*�3��u!7��9��;��=��?
�A*�CJ�Ej�G��I��K��M��O
�Q*�SJ�Uj�W��Y��[��]��4
�a*�cJ�ej�g��i��k��m��o
�q*�sJ�uj�w��y��!;
with.clause.difftext/plain; charset=ISO-8859-1; name=with.clause.diffDownload
276a277,285
> 
> /* WITH CLAUSE */
> 
> %type <boolean>	opt_recursive
> %type <node>	with_list_element
> %type <list>	with_list
> 
> /* /WITH CLAUSE */
> 
374c383,387
< 	READ, REAL, REFERENCES, REINDEX, RELATIVE, RENAME, REPLACE,
---
> 	READ, REAL,
> 	
> 	RECURSIVE,
> 	
> 	REFERENCES, REINDEX, RELATIVE, RENAME, REPLACE,
4023,4024c4036,4037
< SelectStmt: select_no_parens			%prec UMINUS
< 			| select_with_parens		%prec UMINUS
---
> SelectStmt:	select_no_parens					%prec UMINUS
> 			| select_with_parens				%prec UMINUS
4028,4029c4041,4042
< 			'(' select_no_parens ')'				{ $$ = $2; }
< 			| '(' select_with_parens ')'			{ $$ = $2; }
---
> 			'(' select_no_parens ')'						{ $$ = $2; }
> 			| '(' select_with_parens ')'					{ $$ = $2; }
4031a4045
> 
4033c4047,4058
< 			simple_select						{ $$ = $1; }
---
> 			simple_select								{ $$ = $1; }
> 			| WITH opt_recursive with_list simple_select
> 				{
> 					/* this should actually blend in subselects from WITH
> 					 * just replacing will do the WRONG THING
> 					 */
> 					((SelectStmt *) $4 )->with_recursive = $2;
> 					((SelectStmt *) $4 )->withClause = $3;
> 					
> 					$$ = $4;
> 				}
> 
4039a4065,4072
> /*
> 			| WITH RECURSIVE with_list select_clause sort_clause opt_for_update_clause opt_select_limit
> 				{
> 					insertSelectOptions((SelectStmt *) $2, $3, $4,
> 										nth(0, $5), nth(1, $5));
> 					$$ = $1;
> 				}
> */
4045a4079,4087
> /*
> 			| WITH RECURSIVE with_list select_clause for_update_clause opt_select_limit
> 				{
> 					insertSelectOptions((SelectStmt *) $2, NIL, $3,
> 										nth(0, $4), nth(1, $4));
> 					$$ = $1;
> 				}
> */
> 
4051a4094,4100
> 			| WITH opt_recursive with_list select_clause select_limit
> 				{
> 					insertSelectOptions((SelectStmt *) $4, NIL, NIL,
> 										nth(0, $5), nth(1, $5));
> 					$$ = $4;
> 				}
> 
4053a4103,4141
> /*  WITH CLAUSE
>  *
>  * ANSI/ISO SQL99 p 7.13-7.14
>  *
>  */
> 
> opt_recursive:
> 			RECURSIVE		{ $$ = TRUE; }
> 			| /*EMPTY */	{ $$ = FALSE; }
> 		;
> 
> with_list:
>             with_list_element						{ $$ = makeList1($1); }
>             | with_list ',' with_list_element		{ $$ = lappend($1, $3); }
>         ;
>   
> with_list_element:
>             ColId '(' name_list ')' AS select_with_parens
> 				{
> 					RangeSubselect *n = makeNode(RangeSubselect);
> 					n->subquery = $6;
> 					n->alias = makeNode(Alias);
> 					n->alias->aliasname = $1;
> 					n->alias->colnames = $3;
> 					$$ = (Node *) n;
> 				}
> 			| ColId  AS select_with_parens
> 				{
> 					RangeSubselect *n = makeNode(RangeSubselect);
> 					n->subquery = $3;
> 					n->alias = makeNode(Alias);
> 					n->alias->aliasname = $1;
> 					$$ = (Node *) n;
> 				}
>         ;
> 
> /* /WITH CLAUSE */
> 
> 
6772d6859
< 			| WITH
6916a7004
> 			| RECURSIVE
6931a7020
> 			| WITH
#3Evgen Potemkin
evgent@ns.terminal.ru
In reply to: Hannu Krosing (#2)
Re: Hirarchical queries a la Oracle. Patch.

thanks, it's VERY helpful.
understanding SQL99 draft is a bit more difficult than i thought :)

regards,

---
.evgen

On 27 Nov 2002, Hannu Krosing wrote:

Show quoted text

I attach a railroad diagram of SQL99 "WITH RECURSIVE" and a diff against
mid-summer gram.y which implements half of SQL99 _syntax_ (just the WITH
{RECURSIVE} part, SEARCH (tree search order order) and CYCLE (recursion
control) clauses are missing).

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Evgen Potemkin (#3)
Re: Hirarchical queries a la Oracle. Patch.

Hannu Krosing <hannu@tm.ee> writes:

On Thu, 2002-11-28 at 17:34, Evgen Potemkin wrote:

understanding SQL99 draft is a bit more difficult than i thought :)

You might also try to get DB2 installed somewhere (IIRC IBM gives out
limited time developer copies).

Even without DB2 installed, you can read the documentation for it on the
web. There's quite a lot of useful info in IBM's docs. For example
http://nscpcw.physics.upenn.edu/db2_docs/db2s0/withsel.htm
and the example starting at
http://nscpcw.physics.upenn.edu/db2_docs/db2s0/db2s0446.htm

(The docs are probably also readable directly from IBM, but this is the
first copy I found by googling...)

regards, tom lane

#5Hannu Krosing
hannu@tm.ee
In reply to: Evgen Potemkin (#3)
Re: Hirarchical queries a la Oracle. Patch.

On Thu, 2002-11-28 at 17:34, Evgen Potemkin wrote:

thanks, it's VERY helpful.
understanding SQL99 draft is a bit more difficult than i thought :)

You might also try to get DB2 installed somewhere (IIRC IBM gives out
limited time developer copies).

It implements at least the basic recursive query (without requiring the word RECURSIVE :)

Show quoted text

--------------
Hannu