PostgreSQL some operation memo

Source: Internet
Author: User
Tags postgresql

1. Left JOIN or RIGHT Join

When a database returns records by connecting two or more tables, an intermediate temporary table is generated, and the temporary table is returned to the user.

2. Processing JSON

Official explanation address https://www.postgresql.org/docs/9.5/static/functions-json.html

--: is to get the JSON object

--: Is the string to get

#>: Obtaining a JSON object based on the path

#>>: Get string based on path

Give me a chestnut.

There is a JSON string {"A": {"B": "C"}}

Select ' {"a": {"B": "C"}} ':: JSON, ' A '->> ' B ' as result

return results

C

If I use a->> when I get a, that is, execute the statement select ' {"a": {"B": "C"} ':: JSON->> ' a '->> ' B ' as result then an error will be made

Execution information:

[Sql]select ' {"a": {"B": "C"}} ':: JSON->> ' a '->> ' B ' as result

[ERR] Error: operator does not exist: text->> unknown
Line 1:select ' {"a": {"B": "C"}} ':: JSON->> ' a '->> ' B ' as result
^
HINT: There is no operator matching the specified name and parameter type. You may need to increase the explicit type conversions.

The cause of the error is that ->> returned is text is not a JSON object so behind the->> depressed on the error.

What if I want to write this?

Simple, just turn the text into JSON.

Select (' {"a": {"B": "C"}} ':: JSON->> ' a ')::json->> ' B ' as result

Right, here's () is to be noted if:: JSON before the things are not used to be in parentheses, then the error will be

Select ' {"a": {"B": "C"}} ':: JSON->> ' a '::json->> ' B ' as result

[Sql]select ' {"a": {"B": "C"}} ':: JSON->> ' a '::json->> ' B ' as result

[ERR] Error: JSON type uses invalid input syntax
Line 1:select ' {"a": {"B": "C"}} ':: JSON->> ' a '::json->> ' B ' as result
^
DETAIL: Token "A" is invalid.
Context:json data, line 1:a

This can be inferred:: Higher priority

3.

PostgreSQL some operation memo

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.