Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. A | B | C
  2. a1| b1| c1
  3. a1| b2| c2
  4. a1| b3| c3
  5. a2| b1| c2
  6. a2| b2| c5
  7.  
  8. a1 | (c1,b1) ; (c2,b2);(c3;b3)
  9. a2 | (c2,b1) ; (c5,b2)
  10.  
  11. An error occurred when executing the SQL command:
  12. CREATE FUNCTION cut_semicolon(text) RETURNS text AS $$
  13. BEGIN
  14. RETURN SUBSTRING($1 FROM 4)
  15.  
  16. ERROR: unterminated dollar-quoted string at or near "$$
  17. BEGIN
  18. RETURN SUBSTRING($1 FROM 4)"
  19. Position: 53
  20.  
  21. CREATE FUNCTION cut_semicolon(text) RETURNS text AS $$
  22. ^
  23.  
  24. Execution time: 0.24s
  25. (Statement 1 of 7 finished)
  26.  
  27. 0 rows affected
  28. END executed successfully
  29.  
  30. Execution time: 0.22s
  31. (Statement 2 of 7 finished)
  32.  
  33. An error occurred when executing the SQL command:
  34. $$ LANGUAGE 'plpgsql' IMMUTABLE
  35.  
  36. ERROR: unterminated dollar-quoted string at or near "$$ LANGUAGE 'plpgsql' IMMUTABLE"
  37. Position: 1
  38.  
  39. $$ LANGUAGE 'plpgsql' IMMUTABLE
  40. ^
  41.  
  42. Execution time: 0.22s
  43. (Statement 3 of 7 finished)
  44.  
  45. An error occurred when executing the SQL command:
  46. CREATE FUNCTION concat_semicolon(text, text) RETURNS text AS $$
  47. BEGIN
  48. RETURN $1 || ' ; ' || $2
  49.  
  50. ERROR: unterminated dollar-quoted string at or near "$$
  51. BEGIN
  52. RETURN $1 || ' ; ' || $2"
  53. Position: 62
  54.  
  55. CREATE FUNCTION concat_semicolon(text, text) RETURNS text AS $$
  56. ^
  57.  
  58. Execution time: 0.22s
  59. (Statement 4 of 7 finished)
  60.  
  61. 0 rows affected
  62. END executed successfully
  63.  
  64. Execution time: 0.22s
  65. (Statement 5 of 7 finished)
  66.  
  67. An error occurred when executing the SQL command:
  68. $$ LANGUAGE 'plpgsql' IMMUTABLE
  69.  
  70. ERROR: unterminated dollar-quoted string at or near "$$ LANGUAGE 'plpgsql' IMMUTABLE"
  71. Position: 1
  72.  
  73. $$ LANGUAGE 'plpgsql' IMMUTABLE
  74. ^
  75.  
  76. Execution time: 0.22s
  77. (Statement 6 of 7 finished)
  78.  
  79. An error occurred when executing the SQL command:
  80. CREATE AGGREGATE concat_semicolon(
  81. BASETYPE=text,
  82. SFUNC=concat_semicolon,
  83. STYPE=text,
  84. FINALFUNC=cut_semicolon,
  85. INITCOND=''
  86. )
  87.  
  88. ERROR: SQL command "CREATE AGGREGATE concat_semicolon(
  89. BASETYPE=text,
  90. SFUNC=concat_semicolon,
  91. STYPE=text,
  92. FINALFUNC=cut_semicolon,
  93. INITCOND=''
  94. )" not supported.
  95.  
  96. Execution time: 0.23s
  97. (Statement 7 of 7 finished)
  98.  
  99.  
  100. 5 statements failed.
  101. Script execution finished
  102. Total script execution time: 1.55s
  103.  
  104. select A, concat(concat(concat(C, ',' ) , cast(B as varchar)), ',')
  105. from my_table
  106. group by A,B,C
  107.  
  108.  
  109. -- Is it ok to group by all A,B, C - since I can't group by A alone, which removes the related "C" columns--
  110.  
  111. gives -:
  112. a1 c1b1b2b3
  113. a2 c2b1b2
  114.  
  115. a1 c1,b1;c2,b2;c2,b3
  116. a2 c2,b1;c5,b2
  117.  
  118. SELECT
  119. a,
  120. STRING_AGG('(' || c || ',' || b || ')', ' ; ')
  121. FROM
  122. tbl
  123. GROUP BY
  124. a;
  125.  
  126. CREATE FUNCTION cut_semicolon(text) RETURNS text AS '
  127. BEGIN
  128. RETURN SUBSTRING($1 FROM 4);
  129. END;
  130. ' LANGUAGE 'plpgsql' IMMUTABLE;
  131.  
  132.  
  133. CREATE FUNCTION concat_semicolon(text, text) RETURNS text AS '
  134. BEGIN
  135. RETURN $1 || '' ; '' || $2;
  136. END;
  137. ' LANGUAGE 'plpgsql' IMMUTABLE;
  138.  
  139. CREATE AGGREGATE concat_semicolon(
  140. BASETYPE=text,
  141. SFUNC=concat_semicolon,
  142. STYPE=text,
  143. FINALFUNC=cut_semicolon,
  144. INITCOND=''
  145. );
  146.  
  147. SELECT
  148. a,
  149. CONCAT_SEMICOLON('(' || c || ',' || b || ')')
  150. FROM
  151. tbl
  152. GROUP BY
  153. a;
  154.  
  155. SELECT
  156. a,
  157. GROUP_CONCAT(CONCAT('(', c, ',', b, ')') SEPARATOR ' ; ')
  158. FROM
  159. tbl
  160. GROUP BY
  161. a;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement