Re: Learning Plpgsql ??
От | Jonathon Batson |
---|---|
Тема | Re: Learning Plpgsql ?? |
Дата | |
Msg-id | 3E35BA54.6070003@octahedron.com.au обсуждение исходный текст |
Ответ на | Re: Learning Plpgsql ?? (Jim Beckstrom <jrbeckstrom@sbcglobal.net>) |
Список | 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 >
В списке pgsql-novice по дате отправления: