473,788 Members | 2,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sql script confusion

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=sub string(var_reln ame, "0 until _")
set var_fieldname=s ubstring(var_re lname,"first _ until 2nd _")
select var_maxID=max(v ar_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
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #1
1 1210
Sim Zacks wrote:
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?
You need to use a specific language.
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=sub string(var_reln ame, "0 until _")
set var_fieldname=s ubstring(var_re lname,"first _ until 2nd _")
select var_maxID=max(v ar_fieldname) from var_tblname
ALTER SEQUENCE var_relname
RESTART WITH var_maxID+1;
fetch next into var_relname
end loop
For this plpgsql might be a good choice. Think sql with a few
loop/control structures and variables.
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


You need to create a function and then call it. You can create dynamic
SQL as a string and then EXECUTE it with plpgsql. The other languages
offer various ways too.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4187
by: hupjack | last post by:
I finally joined the millions of cell phone users out there. I'm the 2nd phone on what is now a family share plan. (Our two cell phones use minutes from a central 400 minute peak time pool.) Looking at the verizon wireless website, minutes used are displayed only as two different totals for our 2 phones. Dialing in from a phones to check remaining minutes, the minutes are presented the same way, broken down by each phone but not...
6
12987
by: Mike Daniel | last post by:
I am attempting to use document.write(pageVar) that displays a new html page within a pop-up window and the popup is failing. Also note that pageVar is a complete HTML page containing other java scripts. Being a javascript newbie and after significant testing, I suspect that the document.write fails after finding a </script> within pageVar. Does a trick exist that enables one to slightly alter pageVar whereby enabling...
12
2180
by: Ali | last post by:
I have the following web page with a script in it. <html> <head> <title>Make Your Own Objects test</title> <script>
17
7926
by: comp.lang.tcl | last post by:
The TCL command I am using will do a command-line action on a PHP script: set cannotRunPHP I have to do it this way as both the TCL script and the PHP script run as CLI. However, "info.php" requires user input to run; this causes the TCL script calling the PHP script to hose up and die. Is there a way I can do this so that the TCL script can call the PHP
17
2786
by: CES | last post by:
All, I was wondering if their is a way of loading an external script fill from within a script?? <script language="javascript" type="text/javascript"> function test(var){ <script language="javascript" src="../scripts/base.js" type="text/javascript" /> } </script> Obviously this would cause n error but this would give you an idea of what I'm looking to do. I know I can do this with a simple include but...
6
1550
by: Jon Paal | last post by:
an excellent working solution for scrolling tables appears at this link http://www.litotes.demon.co.uk/example_scripts/tableScroll.html author has no contact page, but I have a question about the display of the table. the top left corner in the table grid is hidden from being displayed. I have tried to figure out where it is being hidden but can't find the code to allow it to be shown as part of the left frozen column. can anyone...
5
2575
by: Shuaib | last post by:
Hi! I have a python script which returns an Integer value. How do I call this script from a C programe, and use the result returned? Thanks for your time.
5
13123
by: Ankur | last post by:
Hi Folks, I am new for this group. I want to clarify one thing what's a basic difference between Client Side Java Script and Server Side Java Script. how we can differentiate it. Why we called this kind of script "Server Side Java Script". I am in confusion because according to lots of web developer Java Script is a client side scripting language. We can not say it Server Side Java Script.
14
1572
by: Tony | last post by:
I have a select with an onchange - it works find in Firefox, but in IE 6 I get an error: Object Expected. I have simplified things drastically, and still get the error. The HTML: <select name="viewtrain" id="viewtrain" onchange="viewDetails(this);"> <option value="1">Train 1</option> <option value="2">Train 2</option>
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10364
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10172
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.