473,386 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Writing DDLs in Functions

Hii All

I need to write DDL statements in function, as we used to do in Oracle with EXECUTE IMMEDIATE command.
Is there any way we can do this.

Regards
Sarabjeet
Dec 15 '06 #1
1 1190
michaelb
534 Expert 512MB
If you use SQL or PLPGSQL as language for the function you may not need to do anythinmg special. Here's a couple of oversimplified examples:
Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE FUNCTION foo() RETURNS text AS '
  2. BEGIN
  3.     create table bar (
  4.         field1 int not null,
  5.         field2 varchar(512)
  6.     );
  7.  
  8.     return ''OK'';
  9.  
  10. END;
  11. ' LANGUAGE plpgsql
  12. ;
  13. -- ---------------------------
  14. CREATE OR REPLACE FUNCTION bar() RETURNS name AS '
  15.  
  16.     create table foo (
  17.         id  serial  NOT NULL,
  18.         description varchar(512)
  19.     );
  20.  
  21.     select tablename from pg_tables where tablename = ''foo'';
  22.  
  23. ' LANGUAGE SQL
  24. ;
  25.  
However for executing dynamic commands in PL/pgSQL functions
(those that involve different tables or different data types each time they are executed) you may need to use the the EXECUTE statement.
This query string serving as an argument to EXECUTE is simply passed to the SQL engine.
Dec 17 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Dariusz | last post by:
I would like to try writing my own functions, so as to keep some code within the same PHP file rather than make multiple PHP files. What I am having a problem is is how to call a function when a...
17
by: Bart Nessux | last post by:
I understand that most people write functions to reuse code, no? So, I assume it would be better to write functions that are very specific, as opposed to those that are more generic. However, I...
4
by: aaronfude | last post by:
Hi, Perhaps this is slightly offtopic. Coming into the Windows world from Unix. Is there a reference on writing C++ libraries in a portable way. For example, right now I'm sticking...
15
by: vinjvinj | last post by:
I have an application which allows multiple users to write models. These models get distributed on a grid of compute engines. users submit their models through a web interface. I want to 1....
0
by: Matt Clepper | last post by:
Ok - debated on posting this on SQL group but here goes... I have a piece of ASP code (function #1) that creates a new SQLTransaction (BeginTransaction) to and begins to write records to the...
6
by: hpy_awad | last post by:
I am writing stings ((*cust).name),((*cust).address)to a file using fgets but rabish is being wrote to that file ? Look to my source please and help me finding the reason why this rabish is being...
2
by: Yan | last post by:
I want to begin a project to write a proxy for instant messaging protocols in C and make it posix compliant. I originally wanted to write the proxy for one protocol, but not im thinking if i was to...
102
by: Xah Lee | last post by:
i had the pleasure to read the PHP's manual today. http://www.php.net/manual/en/ although Pretty Home Page is another criminal hack of the unix lineage, but if we are here to judge the quality...
0
by: bohuge | last post by:
Hey! At the time being I'm working on a backup solution for a Qtek9090 pocketpc, which should be able to find and backup outlook data to a server, local files, messages and contact from the sim...
3
by: jitu.csewizard | last post by:
hi overview: function sprintf(<buffername>,<format string>, .....) in this function you need to allocate the size of buffername before hand. question: function ssprintf(<buffername>,<format...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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...

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.