使用冒泡排序在postgresql中对数组进行排序

时间:2017-11-08 22:52:53

标签: arrays postgresql sorting

我正在尝试使用冒泡排序对此数组进行排序,但它向我显示的错误类型我无法理解问题点。

Connecting to server 127.0.0.1:12222 via HTTP proxy ipv4:xx.xx.xx.xx:xxxx

1 个答案:

答案 0 :(得分:0)

要说清楚,我不赞同冒泡,但如果你不得不这样做,我认为它会是这样的:

PDFKit.configure do |config|
  ...
end

require "pdfkit"
Rails.application.config.middleware.use PDFKit::Middleware, print_media_type: true

试验:

MACOSX_DEPLOYMENT_TARGET=10.13 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --with-php-config=/usr/bin/php-config

结果:

CREATE OR REPLACE FUNCTION Arraysort(input_array anyarray,
    e anyelement = null, out results anyarray)
  returns anyarray as
$BODY$
DECLARE
  last_element integer;
  i integer;
  j integer;
BEGIN

  last_element := array_length (input_array, 1) - 1;
  results := input_array;

  for j in 1..last_element loop
    for i in 1..last_element loop

      if results[i] > results[i + 1] then

        e := results[i];
        results[i] := results[i + 1];
        results[i + 1] := e;

      end if;

    end loop;   
  end loop;

END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;