teoljungberg / fx

Versioned database functions and triggers for Rails
MIT License
763 stars 77 forks source link

ArgumentError: String Contain Null Byte. During rails db:test:prepare. #83

Closed bekicot closed 2 years ago

bekicot commented 2 years ago
  create_function :naturalsort, sql_definition: <<-SQL
      CREATE OR REPLACE FUNCTION public.naturalsort(text)
       RETURNS bytea
       LANGUAGE sql
       IMMUTABLE STRICT
      AS $function$
          select string_agg(convert_to(coalesce(r[2], length(length(r[1])::text) || length(r[1])::text || r[1]), 'SQL_ASCII'),'\x00')
          from regexp_matches($1, '0*([0-9]+)|([^0-9]+)', 'g') r;
      $function$
  SQL

notice the \x00 I think it should be escaped in the generated schema.rb.

It works if we use structure.sql .

bekicot commented 2 years ago

Looks like it is fixed in here: https://github.com/teoljungberg/fx/commit/a9c262836c02dabced6c18172f022df2efff6b5b

teoljungberg commented 2 years ago

Thanks for the bug report, point the gem towards master and I'll cut a new release soon.