473,749 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Declaring empty, non-NULL array in plpgsql

CSN
Is there a way to declare an array in plpgsql so that
it's empty (not NULL)? The following causes arr to end
up being NULL:

arr varchar[];
-- do stuff with arr..
arr = array_append(ar r, '','');
And this causes an unwanted element at the front:

arr varchar[] := array[''''];
-- do stuff with arr..
arr = array_append(ar r, '','');
_______________ _______________ ____
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 12 '05 #1
1 13424
CSN <co************ *******@yahoo.c om> writes:
Is there a way to declare an array in plpgsql so that
it's empty (not NULL)?


Sure. An empty-array literal is '{}', so:

regression=# create function foo(int) returns varchar[] as '
regression'# declare
regression'# arr varchar[] := ''{}'';
regression'# begin
regression'# for i in 1..$1 loop
regression'# arr = array_append(ar r, i::varchar);
regression'# end loop;
regression'# return arr;
regression'# end' language plpgsql;
CREATE FUNCTION
regression=# select foo(10);
foo
------------------------
{1,2,3,4,5,6,7, 8,9,10}
(1 row)
regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 12 '05 #2

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

Similar topics

4
2873
by: Derek Basch | last post by:
Hello All, I ran into a problem while dynamically constructing XHTML documents using minidom. If you create a script tag such as: script_node_0 = self.doc.createElement("script") script_node_0.setAttribute("type", "text/javascript") script_node_0.setAttribute("src", "../test.js") minidom renders it as:
1
1731
by: John | last post by:
Hi, I have an element StaticLayerDataStream referenced in the schema file. This element can be empty or non-empty in the instance file depending on circumstances. <xs:element name="StaticLayerDataStream" type="xs:hexBinary"> Now in the XML instance file, the parser throws an error when it comes across an empty StaticLayerDataStream element like so:
5
1453
by: James Aguilar | last post by:
Hello, all. I saw this in the provided code of a lab that I have due in a couple of weeks in my algorithms class. It compiled fine in g++ but did not compile with the VC++ compiler. It does not recognize the angle brackets that follow "<<" in the operator friend declaration. --- CODE --- template <class T> class PriorityQueue {
15
2847
by: Sander Tekelenburg | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 The HTML specs speak of "replaced" and "non-replaced" elements, yet for the life of me I can't find an explanation of what "replaced" is supposed to mean in this context. Can someone explain? TIA
19
32327
by: wetherbean | last post by:
Hi group..I am writing a playlist management protocol where I have a file that holds all the playlists and a file that holds all the songs....before a playlist is created I need to check to see if the playlist file is empty so that I can assign an integer value to a playlist id field if it is the first playlist being written to the file....can anyone help?? Thanks in advance wetherbean
32
4524
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
20
4259
by: Ole Hanson | last post by:
I am accessing my database through an interface, to allow future substitution of the physical datastore - hence I would like to declare in my Interface that my DAL-objects implementing the interface and accessing the datastore MUST pass in a UserToken in the constructor of the object. Is this not possible? Am I forced to add the UserToken as a property on the object instead? /Ole
2
1399
by: Biermann.Pan | last post by:
Hi all, I dont' understand the statement in 10.19 of C++ FAQ lite, I have never seen a function can be declared as Bar(), according to my experience, all functions are declared in form of return_type func_name(parametes_list); if Bar is the return type, where is the func_name? or if Bar is the func_name, where is the return_type as the Author
1
1593
by: Hemanth Kumar P | last post by:
Hello Sir/Madam, I had declared a function as a non-void type as shown below: uinsigned int functn(int x, int y); While using this function in my program, I am getting the warning as "control reaches end of non-void function". For this, any solution is there to eradicate this warning please intimate me. Thanking you,
1
2047
by: curious2007 | last post by:
Hello everybody, When I try to declare nontemplate friend functions I get the following warning: friend decleration......declares a non-template function (if this is not what you intended, make sure the function tempate has already been declared and add<> after the function name here)-Wno-non-template-friend disables this warning. Since declaring a non-template friend function is what i have intended, I would like to disable this...
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
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
9562
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
9386
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...
0
9254
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...
0
8255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6078
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();...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
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

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.