sivgos-tv
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # JSON and JSONB Fields in PostgreSQL JSON (JavaScript Object Notation) and JSONB (Binary JSON) are data types in PostgreSQL that allow storing and manipulating JSON data. JSON is a lightweight data interchange format, while JSONB is a binary representation of JSON data, providing additional functionality and performance optimizations. Let's explore JSON and JSONB in PostgreSQL and go through some basic CRUD (Create, Read, Update, Delete) operations. ### 1. JSON Data Type: The JSON data type stores JSON-formatted data as text. It validates the JSON syntax but does not enforce any constraints on the structure or keys within the JSON document. Example: Creating a table with a JSON column. ```sql CREATE TABLE users ( id serial PRIMARY KEY, data json ); ``` CRUD Operations with JSON: - Create: Inserting a JSON value into a column. ```sql INSERT INTO users (data) VALUES ('{"name": "John", "age": 30}'); ``` - Read: Retrieving JSON values from a column. ```sql SELECT data->>'name' AS name, data->>'age' AS age FROM users; ``` - Filter by on JSON value. ```sql SELECT * FROM users WHERE data->>'age' >= '30'; ``` - Update: Modifying JSON values within a column. ```sql UPDATE users SET data = jsonb_set(data, '{age}', '"31"') WHERE id = 1; ``` - Delete: Removing a JSON value from a column. ```sql UPDATE users SET data = data - 'age' WHERE id = 1; ``` ### 2. JSONB Data Type: The JSONB data type stores JSON data in a binary format, allowing for efficient storage and indexing. It supports all JSON functionality and provides additional capabilities, such as indexing, faster searching, and query optimization. Example: Creating a table with a JSONB column. ```sql CREATE TABLE products ( id serial PRIMARY KEY, data jsonb ); ``` CRUD Operations with JSONB: - Create: Inserting a JSONB value into a column. ```sql INSERT INTO products (data) VALUES ('{"name": "Product 1", "price": 10.99}'); ``` - Read: Retrieving JSONB values from a column. ```sql SELECT data->>'name' AS name, data->>'price' AS price FROM products; ``` - Filter by on JSONB value. ```sql SELECT * FROM users WHERE data->>'age' >= '30'; ``` - Update: Modifying JSONB values within a column. ```sql UPDATE products SET data = jsonb_set(data, '{price}', '"9.99"') WHERE id = 1; ``` - Delete: Removing a JSONB value from a column. ```sql UPDATE products SET data = data - 'price' WHERE id = 1; ``` ### Difference between -> and ->> operators In PostgreSQL, the `->` and `->>` operators are used to extract values from JSON or JSONB data. However, they differ in their output and usage: 1. `->` Operator: The `->` operator is used to extract a JSON object or element from a JSON or JSONB column. It returns the value as JSON data type. Example: ```sql SELECT data->'name' AS name FROM users; ``` This query retrieves the value associated with the key "name" from the JSON/JSONB column `data`. 2. `->>` Operator: The `->>` operator is used to extract a JSON object or element from a JSON or JSONB column and returns the value as text. Example: ```sql SELECT data->>'name' AS name FROM users; ``` This query retrieves the value associated with the key "name" from the JSON/JSONB column `data` and returns it as text. The main difference between `->` and `->>` is the data type of the returned value. The `->` operator returns the value as JSON, allowing for further manipulation or extraction of nested elements using additional JSON operators. On the other hand, the `->>` operator returns the value as text, suitable for direct display or comparison purposes. It's important to note that both `->` and `->>` can be used with JSON and JSONB columns interchangeably since they have the same behavior for JSON and JSONB data types. In summary, the `->` operator returns the value as JSON, while the `->>` operator returns the value as text when extracting elements from JSON or JSONB columns in PostgreSQL. ### JSON vs JSONB | Aspect | JSON | JSONB | |-------------------|--------------------------------------------------------------|-------------------------------------------------------------------| | Storage Format | Plain text | Binary format | | Query Performance | Parsing on-the-fly, can impact performance | Faster searching, indexing, and querying | | Storage Size | Larger due to plain text storage | Smaller due to binary storage | | Data Modification | Full value replacement for updates | Supports in-place updates for efficient modifications | | Indexing | No direct indexing support | Supports indexing for efficient querying and searching | | Use Case | Simple JSON structures, minimal querying/indexing needs | Efficient querying, indexing, and manipulation of complex JSON data | ### Conclusion: JSON and JSONB data types in PostgreSQL provide flexible storage and manipulation of JSON-formatted data. JSON is stored as plain text, while JSONB is a binary representation offering enhanced performance and indexing capabilities. With these data types, you can perform basic CRUD operations to create, read, update, and delete JSON or JSONB values within your tables.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully