>  기사  >  데이터 베이스  >  기능이 있는 경우 postgresql은 MySQL과 어떻게 호환됩니까?

기능이 있는 경우 postgresql은 MySQL과 어떻게 호환됩니까?

PHPz
PHPz앞으로
2023-06-01 19:52:122609검색

    postgresql은 MySQL if 함수

    if 함수 설명

    과 호환됩니다. mysql의 if() 함수 사용법은 Java의 삼항 표현식과 유사하며 구체적인 구문은 다음과 같습니다.

    IF( expr1, expr2, expr3), expr1의 값이 true이면 expr2의 값을 반환하고, expr1의 값이 false이면 expr3의 값을 반환

    postgresql 함수 호환 가능

    create or replace function if(bln boolean,inValue1 anyelement,inValue2 anyelement)
    returns anyelement as
    $$
    begin
    if bln=true then
       return inValue1;
    else
       return inValue2;
    end if;
    end;
    $$
    language plpgsql;
    
    create or replace function if(bln boolean,inValue1 numeric,inValue2 numeric)
    returns numeric as
    $$
    begin
    if bln=true then
       return inValue1;
    else
       return inValue2;
    end if;
    end;
    $$
    language plpgsql;
    
    create or replace function if(bln boolean,inValue1 numeric,inValue2 text)
    returns text as
    $$
    begin
    if bln=true then
       return inValue1;
    else
       return inValue2;
    end if;
    end;
    $$
    language plpgsql;

    mysql이면 custom, oracle, postgresql 호환

    sql

    1.dual table

    oracle의 고유 테이블 사용의 차이점, 목적은 sql 문의 전체 구조를 제한하는 것입니다.

    select (select * from table_name where age = 20) t from dual

    mysql 및 pgsql에는 이 테이블이 없으므로 직접 사용할 수 있습니다. 제거하세요

    select (select * from table_name where age = 20) t

    2. 부울 유형

    oracle 및 mysql에는 부울 유형이 없으므로 대신 숫자(int) 또는 char를 사용할 수 있습니다.

    pgsql에는 부울 유형이 있으며 숫자와 문자는 자동으로 부울 유형(0&rarr)으로 변환됩니다. ;f, 1→t, no→f, yes&rarr ;t)

    3. 테이블 별칭 업데이트

    pgsql은 해당되지 않습니다. mysql 및 oracle은

    update table_name t set t.name = 'abc' where id = 1

    4 문자열 값

    pgsql만 지원합니다. 작은 따옴표 지원

    select * from table_name where name = 'abc'

    mysql 작은 따옴표/큰 따옴표가 지원됩니다

    select * from table_name where name = "abc"

    5. 일괄 삽입

    mysql, pgsql 일괄 삽입

    insert into table_name() values()

    oracle 일괄 삽입

    insert all into table_name() values()

    mybatis는 다른 데이터베이스와 호환됩니다

    if 태그 사용 _databaseId를 판단하고 각각 다른 데이터베이스에 적용하려면 특정 코드를 다음과 같이

    <insert id="insertBatch" parameterType="java.util.List">
        <if test="_databaseId==&#39;mysql&#39; or _databaseId==&#39;postgresql&#39;">
            insert into table_name 
            (<include refid="insertBatchColumn"></include>)
            values
            <foreach collection="list" item="item" index="index" separator="," >
                (<include refid="insertBatchValue"></include>)
            </foreach>
        </if>
        <if test="_databaseId==&#39;oracle&#39;">
            insert all
            <foreach collection="list" item="item" index="index" separator="">
                into table_name 
                (<include refid="insertBatchColumn"></include>)
                values (<include refid="insertBatchValue"></include>)
            </foreach>
            select * from dual
        </if>
    </insert>
     
    <sql id="insertBatchColumn">
        id,name,age,gender
    </sql>
    <sql id="insertBatchValue">
        #{item.id,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR}, 
        #{item.age,jdbcType=INTEGER},#{item.gender,jdbcType=INTEGER}
    </sql>

    위 내용은 기능이 있는 경우 postgresql은 MySQL과 어떻게 호환됩니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

    성명:
    이 기사는 yisu.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제