Permalink
Browse files

ugh

  • Loading branch information...
Joe Van Dyk
Joe Van Dyk committed Mar 19, 2012
1 parent 831a535 commit 2697c99fabccb0887cb94b20a6d6568da26453a3
Showing with 7 additions and 10 deletions.
  1. +7 −10 slug.sql
View
@@ -1,7 +1,8 @@
---begin;
create extension if not exists hstore;
+--begin;
+
-- Test table
drop table if exists foos;
create table foos (
@@ -32,6 +33,7 @@ declare
new_slug_value text;
already_exists integer;
the_same boolean;
+ results foos%rowtype;
begin
slug_column := TG_ARGV[0];
@@ -44,18 +46,13 @@ begin
end if;
end if;
-
- execute 'select coalesce(max(x), 0) from (select unnest(avals(slug_history)::integer[]) x from ' || tg_table_name || ' where search_slug_history($1, slug_history)) f'
+ execute 'select count(*) from (select unnest(avals(slug_history)::integer[]) x from ' || tg_table_name || ' where search_slug_history($1, slug_history)) f'
into already_exists using new_slug_value;
- raise notice 'exists: %', already_exists;
-
- if already_exists then
- new_slug_value := new_slug_value || '--' || already_exists + 1;
- end if;
+ already_exists := already_exists + 1;
- NEW.slug := new_slug_value;
- NEW.slug_history := NEW.slug_history || ARRAY[NEW.slug, already_exists::text]::hstore;
+ NEW.slug := new_slug_value || '--' || already_exists;
+ NEW.slug_history := NEW.slug_history || ARRAY[new_slug_value, already_exists::text]::hstore;
return NEW;
end;

0 comments on commit 2697c99

Please sign in to comment.