Appizap
  • Appizap Overview
  • Build Apps
    • On-boarding Flow
    • Ideas to Apps using AI
    • Create a new app
    • App Configuration
      • App Overview
      • General Settings
      • Domain Settings
      • Version Release & Management
      • App Assets
      • Auth Settings
    • UI Builder
      • Module
      • Menu Navigation
      • Version Logs & Restore
      • Keyboard Shortcuts
    • GUI, Themes & Styles
    • Event handlers
    • Write JavaScript
      • JavaScript within {{ }}
      • JavaScript Query
      • Transformers
      • Temporary State
      • Data Responder
      • Built-in JavaScript Functions
      • Use Third-party Libraries
    • How-to-use
      • Welcome to Appizap!
      • FAQ
  • Appizap Dashboard
    • Your Apps
    • Database
    • Workflows
    • Media & Files
    • Query Library
    • Audit Logger
    • Templates
  • Workspaces
    • Workspace Settings
    • User Authentication
    • User Groups
    • Themes
    • Advanced
  • Appizap Concepts
  • Appizap Studio
    • Data Browser
      • Screen, Modules & Navigations
      • Active Components
      • In-App Modals
      • Data Queries in your App
      • Global Data Variables
    • Layers
    • Screen Settings
    • Debugger
    • Data Queries
    • Widget Library
      • Link
      • Icons
      • Steps
      • Button Group
      • Form Button
      • Grid
      • Responsive Grid Layout
      • Drawer
      • Navigation
      • Cascader
      • Comment
      • Mention
      • Collapsible Container
      • Rich Text Editor
      • Input
      • Modal
      • Text Display
      • Number Input
      • Password
      • List View
      • Date
      • Checkbox
      • Radio
      • Switch
      • Multi Select
      • Dropdown
      • File Upload
      • Phone Number Input
      • Download Pdf Button
      • Image
      • Divider
      • Progress Circle
      • Progress
      • Form
      • JSON Schema Form
      • Container
      • Tabbed Container
      • Table
      • Date Range
      • Time
      • Time Range
      • Toggle Button
      • Segmented Control
      • Rating
      • Timeline
      • Slider
      • Range Slider
      • Control Button
      • File Viewer
      • Image Carousel
      • Lottie Animation
      • Tree
      • Tree Select
      • IFrame
      • Calendar
      • Custom Component
      • Auto Complete
      • Chart
      • Graph Chart
      • Treemap Chart
      • Basic Chart
      • Geo Map Charts
      • Funnel Chart
      • Candlestick Chart
      • Select
      • Audio
      • Caller
      • Text Area
      • Responsive Flex Layout
      • Timer
      • Image Editor
      • AI Component
    • Component Specific Actions
  • Database
    • Connect DB
    • Build Internal DB
      • Arrays
      • Indexes
      • Using JSON Type
      • Cascade Delete
      • Data Load and Import
    • Data Sources
      • Connect Data Sources
        • Big Query
        • ClickHouse
        • CouchDB
        • DynamoDB
        • Elasticsearch
        • MariaDB
        • Microsoft SQL Server
        • MongoDB
        • MySQL
        • Oracle
        • PostgreSQL
        • Redis
        • Snowflake
      • Connect APIs
        • REST API
        • GraphQL
        • Google Sheets
        • S3
        • OpenAPI
        • Firebase
        • WooCommerce
        • OpenAI
        • Athena
        • Lambda
    • Query Library
    • Storage
      • Buckets
      • Uploads
      • Objects
  • Appizap Workflow Builder [Pro]
    • Workflows
      • Create a workflow
      • Nodes
      • Connections
      • Sticky Notes
      • Tags
      • Import and Export
      • Templates
      • Sharing
      • Settings
      • History
      • Find Workflow ID
    • Build Flow Logic
      • Conditional Nodes
      • Data Merging
      • Looping
      • Waiting
      • Sub-Workflow
      • Execution Order
    • Data Handling
      • Data Structure
      • Transforming data
      • Use Code
      • Mapping using UI
      • Data Item Linking
      • Data Pinning
      • Data Editing
      • Data Filtering
      • Data Mocking
      • Binary Data
    • Editor UI
    • Credentials
      • Create and Edit
      • Sharing
    • Integrations
      • Node Types
      • Core Nodes
      • Actions
      • Triggers
      • Credentials
      • Custom API Operations
    • Error Handling
      • Errors related to memory
    • Keyboard Shortcuts
  • Security & Compliance
  • Terms & Conditions
  • Privacy Policy
  • User Guide
    • Getting Started
    • Admin Console
    • Data Maintenance
Powered by GitBook
On this page
  1. Database
  2. Build Internal DB

Arrays

In PostgreSQL, defining an array is a simple process. An array is specified by adding square brackets to a valid data type. This could range from an array of integers, text, boolean values, etc.

CREATE TABLE my_table (
    id SERIAL PRIMARY KEY,
    my_array INT[]
);

In this case, my_array is an array of integers. This column can now store multiple integer values.

Insert Records

To initialize an array with values, one can utilize the ARRAY constructor. Below is an illustration demonstrating the process of inserting data into the table that has just been created:

INSERT INTO my_table (my_array) VALUES (ARRAY[1, 2, 3, 4, 5]);

View Records

To access individual elements in an array, you use square brackets. Remember, arrays in PostgreSQL are 1-indexed, meaning the first element is at position 1. Here's an example:

SELECT my_array[1] FROM my_table WHERE id = 1;

Functions

array_append(array, element): This function appends an element to the end of an array

SELECT array_append(ARRAY[1, 2, 3], 4);

//This will result in ARRAY[1, 2, 3, 4].

array_prepend(element, array): This function adds an element to the beginning of an array.

SELECT array_prepend(0, ARRAY[1, 2, 3]);

//This will result in ARRAY[0, 1, 2, 3].

array_length(array, dimension): This function returns the length of the requested array dimension.

SELECT array_length(ARRAY[1, 2, 3], 1);

//This will return 3 because there are three elements in the first dimension of the array.

unnest(array): This function "flattens" an array into a set of rows.

SELECT unnest(ARRAY[1, 2, 3]);

//This will return three rows with the values 1, 2, and 3 respectively.

Querying Array

The ANY keyword allows you to check if any element in an array matches a condition.

SELECT * FROM my_table WHERE 3 = ANY(my_array);

This statement returns all rows where my_array contains the value 3.

The ALL keyword is used to check if all elements in an array satisfy a condition.

SELECT * FROM my_table WHERE 3 > ALL(my_array);

This statement returns all rows where all values in my_array are less than 3.

PreviousBuild Internal DBNextIndexes

Last updated 10 months ago