Re: Learning Plpgsql ??

From: Jonathon Batson <jonathon(at)octahedron(dot)com(dot)au>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Learning Plpgsql ??
Date: 2003-01-27 23:01:40
Message-ID: 3E35BA54.6070003@octahedron.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Good Idea and it worked, had to play with quotes a bit, duh,
Note: the use of quote_literal for seq's and quote_ident for table and
column objects.

CREATE or REPLACE FUNCTION up_seq() RETURNS text AS '
DECLARE
row RECORD; qrystr TEXT;
BEGIN
-- select sequence information from seq table
[ sequence_name, table_name, pk_column]
FOR row IN SELECT * FROM swim_seq_temp LOOP

qrystr :=
''SELECT setval(''
|| quote_literal(row.sequence_name)
|| '', ( SELECT max(''
|| quote_ident(row.pk_column)
|| '') FROM ''
|| quote_ident(row.table_name)
|| ''))'';
EXECUTE qrystr;

END LOOP;
RETURN ''done'';
END;
' LANGUAGE 'plpgsql';

Jim Beckstrom wrote:

> Coming from another newbie, here's what I use to set the sequence
> following an import of text data. I create seqence and table and
> import one file at a time, for a one time conversion, so I don't need
> the table of table names,etc., but that's a great idea, like a data
> dictionary concept. Would this work, modified to fit your loop syntax?
>
> select SETVAL('link_rep_link_rep_id_seq', (select max(link_rep_id)
> from link_rep))
>
> Jim
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Alain Gougeon 2003-01-27 23:36:57 New and investigating
Previous Message Josh Berkus 2003-01-27 22:30:56 Re: Passing parameters to a Trigger