sql script confusion

From: Sim Zacks <sim(at)compulab(dot)co(dot)il>
To: pgsql-general(at)postgresql(dot)org
Subject: sql script confusion
Date: 2004-09-29 08:32:23
Message-ID: 1225555464.20040929103223@compulab.co.il
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am in the process of testing PostGreSQL for our sales and product
database and I am a little confused about SQL scripting and various
available languages. (My background is mostly MSSQL Server).

I am using the PGAdmin tool and I would like to write a script to
update all sequences to the current max value in the table.

Do I need to use a specific language in a function to do this or does
it work as native SQL, as it would in T-SQL?

What I would like to do is something like -
(pseudo code)
declare cursor for select relname from pg_statio_user_sequences
open cursor
fetch next into var_relname
while not cursor.eof
set var_tblname=substring(var_relname, "0 until _")
set var_fieldname=substring(var_relname,"first _ until 2nd _")
select var_maxID=max(var_fieldname) from var_tblname
ALTER SEQUENCE var_relname
RESTART WITH var_maxID+1;
fetch next into var_relname
end loop

Can dynamic statements be written in "raw sql" or do they need to be
encompassed in a language? Do all language scripts have to be
functions or can I do something like:
Start Language Processing Here
...Code
End Language Processing

Thank You
Sim Zacks
IT Manager
CompuLab
04-829-0145 - Office
04-832-5251 - Fax

Responses

Browse pgsql-general by date

  From Date Subject
Next Message tsarevich 2004-09-29 08:34:58 Composite Type Argument Construction to a Function
Previous Message Shridhar Daithankar 2004-09-29 08:29:17 Re: About PostgreSQL's limit on arithmetic operations